| 1 |
use crate::chunk::Chunk; |
| 2 |
|
| 3 |
#[derive(Default)] |
| 4 |
pub struct Builder { |
| 5 |
signal_name: String, |
| 6 |
trampoline_name: String, |
| 7 |
in_trait: bool, |
| 8 |
is_detailed: bool, |
| 9 |
} |
| 10 |
|
| 11 |
impl Builder { |
| 12 |
pub fn new() -> Self { |
| 13 |
Default::default() |
| 14 |
} |
| 15 |
|
| 16 |
pub fn signal_name(&mut self, name: &str) -> &mut Self { |
| 17 |
self.signal_name = name.into(); |
| 18 |
self |
| 19 |
} |
| 20 |
|
| 21 |
pub fn trampoline_name(&mut self, name: &str) -> &mut Self { |
| 22 |
self.trampoline_name = name.into(); |
| 23 |
self |
| 24 |
} |
| 25 |
|
| 26 |
pub fn in_trait(&mut self, value: bool) -> &mut Self { |
| 27 |
self.in_trait = value; |
| 28 |
self |
| 29 |
} |
| 30 |
|
| 31 |
// https://github.com/rust-lang/rust-clippy/issues/8480 |
| 32 |
pub fn is_detailed(&mut self, value: bool) -> &mut Self { |
| 33 |
self.is_detailed = value; |
| 34 |
self |
| 35 |
} |
| 36 |
|
| 37 |
pub fn generate(&self) -> Chunk { |
| 38 |
let unsafe_ = Chunk::Unsafe(vec![self.let_func(), self.connect()]); |
| 39 |
|
| 40 |
Chunk::BlockHalf(vec![unsafe_]) |
| 41 |
} |
| 42 |
|
| 43 |
fn let_func(&self) -> Chunk { |
| 44 |
let type_ = "Box_<F>".to_string(); |
| 45 |
Chunk::Let { |
| 46 |
name: "f".to_string(), |
| 47 |
is_mut: false, |
| 48 |
value: Box::new(Chunk::Custom("Box_::new(f)".to_owned())), |
| 49 |
type_: Some(Box::new(Chunk::Custom(type_))), |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
fn connect(&self) -> Chunk { |
| 54 |
Chunk::Connect { |
| 55 |
signal: self.signal_name.clone(), |
| 56 |
trampoline: self.trampoline_name.clone(), |
| 57 |
in_trait: self.in_trait, |
| 58 |
is_detailed: self.is_detailed, |
| 59 |
} |
| 60 |
} |
| 61 |
} |