diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-11-30 18:54:46 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-11-30 18:54:46 +0100 |
| commit | 5782b82770f6923677942c3b4e2bf4f7258e47d8 (patch) | |
| tree | 2b477fc285e9da5380e556648056b985ecbccfe0 /src/func/mod.rs | |
| parent | b13ed627fff73a599b34d760cd99aa2f08d58ea8 (diff) | |
Refactor layouting base ♻
Diffstat (limited to 'src/func/mod.rs')
| -rw-r--r-- | src/func/mod.rs | 59 |
1 files changed, 4 insertions, 55 deletions
diff --git a/src/func/mod.rs b/src/func/mod.rs index 9c29caf2..126fd824 100644 --- a/src/func/mod.rs +++ b/src/func/mod.rs @@ -13,7 +13,7 @@ pub mod helpers; pub mod prelude { pub use crate::func::{Command, CommandList, Function}; pub use crate::layout::{layout_tree, Layout, MultiLayout, LayoutContext, LayoutSpace}; - pub use crate::layout::{LayoutAxes, AlignedAxis, Axis, Alignment}; + pub use crate::layout::{LayoutAxes, Axis, Alignment}; pub use crate::layout::{LayoutError, LayoutResult}; pub use crate::syntax::{SyntaxTree, FuncHeader, FuncArgs, Expression, Spanned, Span}; pub use crate::syntax::{parse, ParseContext, ParseError, ParseResult}; @@ -86,6 +86,9 @@ where T: Debug + PartialEq + 'static } } +/// A sequence of commands requested for execution by a function. +pub type CommandList<'a> = Vec<Command<'a>>; + /// Commands requested for execution by functions. #[derive(Debug)] pub enum Command<'a> { @@ -109,60 +112,6 @@ pub enum Command<'a> { SetAxes(LayoutAxes), } -/// A sequence of commands requested for execution by a function. -#[derive(Debug)] -pub struct CommandList<'a> { - pub commands: Vec<Command<'a>>, -} - -impl<'a> CommandList<'a> { - /// Create an empty command list. - pub fn new() -> 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); - } - - /// Whether there are any commands in this sequence. - pub fn is_empty(&self) -> bool { - self.commands.is_empty() - } -} - -impl<'a> IntoIterator for CommandList<'a> { - type Item = Command<'a>; - type IntoIter = std::vec::IntoIter<Command<'a>>; - - fn into_iter(self) -> Self::IntoIter { - self.commands.into_iter() - } -} - -impl<'a> IntoIterator for &'a CommandList<'a> { - type Item = &'a Command<'a>; - type IntoIter = std::slice::Iter<'a, Command<'a>>; - - fn into_iter(self) -> Self::IntoIter { - self.commands.iter() - } -} - -/// Create a list of commands. -#[macro_export] -macro_rules! commands { - ($($x:expr),*$(,)*) => ( - $crate::func::CommandList::from_vec(vec![$($x,)*]) - ); -} - /// A map from identifiers to functions. pub struct Scope { parsers: HashMap<String, Box<ParseFunc>>, |
