diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-10-17 10:12:34 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-10-17 10:12:34 +0200 |
| commit | f22f9513aea21408ebf6febd01912e630e9ad5e6 (patch) | |
| tree | 06885bca8bc31d26189f33c059649ed7909af282 /src/func.rs | |
| parent | 9a1d57a11a510b8e6af024b4338ee58d791f3088 (diff) | |
Add pagebreak function ⏭
Diffstat (limited to 'src/func.rs')
| -rw-r--r-- | src/func.rs | 66 |
1 files changed, 39 insertions, 27 deletions
diff --git a/src/func.rs b/src/func.rs index e2391a55..eaaa476d 100644 --- a/src/func.rs +++ b/src/func.rs @@ -35,6 +35,35 @@ impl PartialEq for dyn Function { } } +/// A helper trait that describes requirements for types that can implement +/// [`Function`]. +/// +/// Automatically implemented for all types which fulfill to the bounds `Debug + +/// PartialEq + 'static`. There should be no need to implement this manually. +pub trait FunctionBounds: Debug { + /// Cast self into `Any`. + fn help_cast_as_any(&self) -> &dyn Any; + + /// Compare self with another function. + fn help_eq(&self, other: &dyn Function) -> bool; +} + +impl<T> FunctionBounds for T +where T: Debug + PartialEq + 'static +{ + fn help_cast_as_any(&self) -> &dyn Any { + self + } + + fn help_eq(&self, other: &dyn Function) -> bool { + if let Some(other) = other.help_cast_as_any().downcast_ref::<Self>() { + self == other + } else { + false + } + } +} + /// A sequence of commands requested for execution by a function. #[derive(Debug)] pub struct CommandList<'a> { @@ -47,6 +76,11 @@ impl<'a> CommandList<'a> { CommandList { commands: vec![] } } + /// Create a command list with commands from a vector. + pub fn from_vec(commands: Vec<Command<'a>>) -> CommandList<'a> { + CommandList { commands } + } + /// Add a command to the sequence. pub fn add(&mut self, command: Command<'a>) { self.commands.push(command); @@ -84,35 +118,13 @@ pub enum Command<'a> { AddMany(MultiLayout), SetAlignment(Alignment), SetStyle(TextStyle), + FinishLayout, } -/// A helper trait that describes requirements for types that can implement -/// [`Function`]. -/// -/// Automatically implemented for all types which fulfill to the bounds `Debug + -/// PartialEq + 'static`. There should be no need to implement this manually. -pub trait FunctionBounds: Debug { - /// Cast self into `Any`. - fn help_cast_as_any(&self) -> &dyn Any; - - /// Compare self with another function. - fn help_eq(&self, other: &dyn Function) -> bool; -} - -impl<T> FunctionBounds for T -where T: Debug + PartialEq + 'static -{ - fn help_cast_as_any(&self) -> &dyn Any { - self - } - - fn help_eq(&self, other: &dyn Function) -> bool { - if let Some(other) = other.help_cast_as_any().downcast_ref::<Self>() { - self == other - } else { - false - } - } +macro_rules! commands { + ($($x:expr),*$(,)*) => ({ + $crate::func::CommandList::from_vec(vec![$($x,)*]) + }); } /// A map from identifiers to functions. |
