use crate::*; /// Show one item if a condition is true and another if the condition is false pub struct Either(pub bool, pub A, pub B); impl Either { /// Create a ternary condition. pub const fn new (c: bool, a: A, b: B) -> Self { Self(c, a, b) } } #[cfg(feature = "dsl")] take!(Either, A, B|state, words|Ok( if let Some(Token { value: Value::Key("either"), .. }) = words.peek() { let base = words.clone(); let _ = words.next().unwrap(); return Ok(Some(Self( state.give_or_fail(words, ||"either: no condition")?, state.give_or_fail(words, ||"either: no content 1")?, state.give_or_fail(words, ||"either: no content 2")?, ))) } else { None })); impl, B: Render> Content for Either { fn layout (&self, to: E::Area) -> E::Area { let Self(cond, a, b) = self; if *cond { a.layout(to) } else { b.layout(to) } } fn render (&self, to: &mut E) { let Self(cond, a, b) = self; if *cond { a.render(to) } else { b.render(to) } } }