use super::expression::Expression; use super::shell::Shell; use std::fmt::Write; use std::marker::PhantomData; #[derive(Debug)] pub(crate) struct LineSeparatedExpressions, B: Expression> { pub(crate) _shell: std::marker::PhantomData, pub(crate) a: A, pub(crate) b: B, } impl, B: Expression> LineSeparatedExpressions { pub fn then>( self, c: C, ) -> LineSeparatedExpressions, C> { LineSeparatedExpressions { _shell: PhantomData, a: self, b: c, } } } impl> LineSeparatedExpressions { pub(crate) fn new(b: B) -> Self { Self { _shell: std::marker::PhantomData, a: (), b, } } } impl, B: Expression> Expression for LineSeparatedExpressions { fn write_shell(&self, writer: &mut impl Write) -> std::fmt::Result { self.a.write_shell(writer)?; writeln!(writer)?; self.b.write_shell(writer) } } mod tests { use super::super::raw::Raw; use super::super::shell::Zsh; use super::*; use pretty_assertions::assert_eq; #[test] fn test_line_separated_expression() { let mut s = String::new(); LineSeparatedExpressions::::new(Raw("Hello".into())) .then(Raw("World".into())) .then(Raw("Other".into())) .write_shell(&mut s) .unwrap(); assert_eq!(s.trim(), "Hello\nWorld\nOther"); } }