diff options
| author | Max <me@mkor.je> | 2024-08-26 17:04:02 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-26 17:04:02 +0000 |
| commit | 373163dba4b4a4d9186b96a671af64d435d0eda3 (patch) | |
| tree | 824e2f5d4b9bf0988a4c0f9978332ea1aed4c554 /crates/typst-utils/src | |
| parent | c38d01e4c5558d839ec91895807f5942c8944348 (diff) | |
Implement math kerning and fix various `math.attach` bugs (#4762)
Diffstat (limited to 'crates/typst-utils/src')
| -rw-r--r-- | crates/typst-utils/src/lib.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/crates/typst-utils/src/lib.rs b/crates/typst-utils/src/lib.rs index 4d5f8e0c..831b2374 100644 --- a/crates/typst-utils/src/lib.rs +++ b/crates/typst-utils/src/lib.rs @@ -83,6 +83,27 @@ impl<T: Clone> ArcExt<T> for Arc<T> { } } +/// Extra methods for [`Option`]. +pub trait OptionExt<T> { + /// Maps an `Option<T>` to `U` by applying a function to a contained value + /// (if `Some`) or returns a default (if `None`). + fn map_or_default<U: Default, F>(self, f: F) -> U + where + F: FnOnce(T) -> U; +} + +impl<T> OptionExt<T> for Option<T> { + fn map_or_default<U: Default, F>(self, f: F) -> U + where + F: FnOnce(T) -> U, + { + match self { + Some(x) => f(x), + None => U::default(), + } + } +} + /// Extra methods for [`[T]`](slice). pub trait SliceExt<T> { /// Split a slice into consecutive runs with the same key and yield for |
