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/meta/reference.rs | |
| parent | 168bdf35bd773e67343c965cb473492cc5cae9e7 (diff) | |
Improve value casting infrastructure
Diffstat (limited to 'library/src/meta/reference.rs')
| -rw-r--r-- | library/src/meta/reference.rs | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/library/src/meta/reference.rs b/library/src/meta/reference.rs index c538b696..42450b97 100644 --- a/library/src/meta/reference.rs +++ b/library/src/meta/reference.rs @@ -193,7 +193,7 @@ impl Show for RefElem { Smart::Auto => refable.supplement(), Smart::Custom(None) => Content::empty(), Smart::Custom(Some(supplement)) => { - supplement.resolve(vt, [(*elem).clone().into()])? + supplement.resolve(vt, [(*elem).clone()])? } }; @@ -229,10 +229,10 @@ pub enum Supplement { impl Supplement { /// Tries to resolve the supplement into its content. - pub fn resolve( + pub fn resolve<T: IntoValue>( &self, vt: &mut Vt, - args: impl IntoIterator<Item = Value>, + args: impl IntoIterator<Item = T>, ) -> SourceResult<Content> { Ok(match self { Supplement::Content(content) => content.clone(), @@ -241,19 +241,16 @@ impl Supplement { } } -cast_from_value! { +cast! { Supplement, + self => match self { + Self::Content(v) => v.into_value(), + Self::Func(v) => v.into_value(), + }, v: Content => Self::Content(v), v: Func => Self::Func(v), } -cast_to_value! { - v: Supplement => match v { - Supplement::Content(v) => v.into(), - Supplement::Func(v) => v.into(), - } -} - /// Marks an element as being able to be referenced. This is used to implement /// the `@ref` element. pub trait Refable { |
