diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-08-02 11:06:45 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-08-02 11:06:45 +0200 |
| commit | efb78831a7a9fe8c807c326a1bfa338b50579938 (patch) | |
| tree | 7bbba4130ac47809c72efeac796b2ca71b72e659 /src/syntax/func/mod.rs | |
| parent | 659248d52ff9e6be4dad7c4555bd62899671ad55 (diff) | |
Unify font and page functions 💕
- Removes font weight and width warnings for now, will be added again later
- Adds a bit hacky get_first function for tuples, will be refactored soon anyway
Diffstat (limited to 'src/syntax/func/mod.rs')
| -rw-r--r-- | src/syntax/func/mod.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/syntax/func/mod.rs b/src/syntax/func/mod.rs index c2631727..37dccc3d 100644 --- a/src/syntax/func/mod.rs +++ b/src/syntax/func/mod.rs @@ -82,13 +82,22 @@ pub enum FuncArg { } /// Extra methods on [`Options`](Option) used for argument parsing. -pub trait OptionExt: Sized { +pub trait OptionExt<T>: Sized { + /// Calls `f` with `val` if this is `Some(val)`. + fn with(self, f: impl FnOnce(T)); + /// Add an error about a missing argument `arg` with the given span if the /// option is `None`. fn or_missing(self, diagnostics: &mut Diagnostics, span: Span, arg: &str) -> Self; } -impl<T> OptionExt for Option<T> { +impl<T> OptionExt<T> for Option<T> { + fn with(self, f: impl FnOnce(T)) { + if let Some(val) = self { + f(val); + } + } + fn or_missing(self, diagnostics: &mut Diagnostics, span: Span, arg: &str) -> Self { if self.is_none() { diagnostics.push(error!(span, "missing argument: {}", arg)); |
