From 5782b82770f6923677942c3b4e2bf4f7258e47d8 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 30 Nov 2019 18:54:46 +0100 Subject: =?UTF-8?q?Refactor=20layouting=20base=20=E2=99=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/func/mod.rs | 59 ++++----------------------------------------------------- 1 file changed, 4 insertions(+), 55 deletions(-) (limited to 'src/func') 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>; + /// 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>, -} - -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>) -> 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>; - - 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>, -- cgit v1.2.3