new with { …; }

Arbitrary Rust code can be inserted into a component's constructor using a new with-block:


#![allow(unused)]
fn main() {
asteracea::component! {
  Constructed()()

  new with {
    // TODO
  }

  []
}
}

Code inside the new with-block has access to constructor parameters, and let-bindings from this block are in scope for capture initialisers:


#![allow(unused)]
fn main() {
asteracea::component! {
  QuoteHolder(
    text: &str,
  )()

  new with {
    let quoted = format!("‘{}’", text);
  }

  let self.quote: String = quoted;

  !(self.quote)
}

asteracea::component! {
  Quoter()()

  <*QuoteHolder *text = { "This text is quoted." }>
}
}
‘This text is quoted.’