diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-11-07 19:02:13 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-11-07 19:07:11 +0100 |
| commit | 1ece263579afcf94ca44acc8e157bce01c3226b8 (patch) | |
| tree | 6da8a7b03bf2138efb728d20f506aec3557afe5c /src/func/mod.rs | |
| parent | 271af7ed0308c9eca7da5dce93d52d38be84889f (diff) | |
Create easy-to-use argument parser 💎
Diffstat (limited to 'src/func/mod.rs')
| -rw-r--r-- | src/func/mod.rs | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/func/mod.rs b/src/func/mod.rs index 402f0111..bd61204e 100644 --- a/src/func/mod.rs +++ b/src/func/mod.rs @@ -7,8 +7,7 @@ use std::fmt::{self, Debug, Formatter}; use self::prelude::*; #[macro_use] -mod helpers; -pub use helpers::Arguments; +pub mod helpers; /// Useful imports for creating your own functions. pub mod prelude { @@ -24,11 +23,12 @@ pub mod prelude { /// Typesetting function types. /// -/// These types have to be able to parse tokens into themselves and store the -/// relevant information from the parsing to do their role in typesetting later. +/// These types have to be able to parse themselves from a string and build +/// a list of layouting commands corresponding to the parsed source. /// -/// The trait `FunctionBounds` is automatically implemented for types which can -/// be used as functions, that is they fulfill the bounds `Debug + PartialEq + +/// This trait is a supertrait of `FunctionBounds` for technical reasons. The +/// trait `FunctionBounds` is automatically implemented for types which can +/// be used as functions, that is, all types which fulfill the bounds `Debug + PartialEq + /// 'static`. pub trait Function: FunctionBounds { /// Parse the header and body into this function given a context. @@ -84,6 +84,19 @@ where T: Debug + PartialEq + 'static } } +/// Commands requested for execution by functions. +#[derive(Debug)] +pub enum Command<'a> { + LayoutTree(&'a SyntaxTree), + Add(Layout), + AddMany(MultiLayout), + AddFlex(Layout), + SetAlignment(Alignment), + SetStyle(TextStyle), + FinishLayout, + FinishFlexRun, +} + /// A sequence of commands requested for execution by a function. #[derive(Debug)] pub struct CommandList<'a> { @@ -130,19 +143,8 @@ impl<'a> IntoIterator for &'a CommandList<'a> { } } -/// Commands requested for execution by functions. -#[derive(Debug)] -pub enum Command<'a> { - Layout(&'a SyntaxTree), - Add(Layout), - AddMany(MultiLayout), - AddFlex(Layout), - SetAlignment(Alignment), - SetStyle(TextStyle), - FinishLayout, - FinishFlexRun, -} - +/// Create a list of commands. +#[macro_export] macro_rules! commands { ($($x:expr),*$(,)*) => ( $crate::func::CommandList::from_vec(vec![$($x,)*]) |
