diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-06-06 21:13:59 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-06-06 22:06:16 +0200 |
| commit | fd417da04f7ca4b995de7f6510abafd3e9c31307 (patch) | |
| tree | 3675529c75ca7363701ac8ea306de2cc1d3cbcb3 /library/src/layout/list.rs | |
| parent | 168bdf35bd773e67343c965cb473492cc5cae9e7 (diff) | |
Improve value casting infrastructure
Diffstat (limited to 'library/src/layout/list.rs')
| -rw-r--r-- | library/src/layout/list.rs | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/library/src/layout/list.rs b/library/src/layout/list.rs index 1e42d51b..b308c2ce 100644 --- a/library/src/layout/list.rs +++ b/library/src/layout/list.rs @@ -174,7 +174,7 @@ pub struct ListItem { pub body: Content, } -cast_from_value! { +cast! { ListItem, v: Content => v.to::<Self>().cloned().unwrap_or_else(|| Self::new(v.clone())), } @@ -193,13 +193,21 @@ impl ListMarker { Self::Content(list) => { list.get(depth).or(list.last()).cloned().unwrap_or_default() } - Self::Func(func) => func.call_vt(vt, [Value::Int(depth as i64)])?.display(), + Self::Func(func) => func.call_vt(vt, [depth])?.display(), }) } } -cast_from_value! { +cast! { ListMarker, + self => match self { + Self::Content(vec) => if vec.len() == 1 { + vec.into_iter().next().unwrap().into_value() + } else { + vec.into_value() + }, + Self::Func(func) => func.into_value(), + }, v: Content => Self::Content(vec![v]), array: Array => { if array.is_empty() { @@ -210,28 +218,14 @@ cast_from_value! { v: Func => Self::Func(v), } -cast_to_value! { - v: ListMarker => match v { - ListMarker::Content(vec) => if vec.len() == 1 { - vec.into_iter().next().unwrap().into() - } else { - vec.into() - }, - ListMarker::Func(func) => func.into(), - } -} - struct Depth; -cast_from_value! { +cast! { Depth, + self => Value::None, _: Value => Self, } -cast_to_value! { - _: Depth => Value::None -} - impl Fold for Depth { type Output = usize; |
