From fd417da04f7ca4b995de7f6510abafd3e9c31307 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 6 Jun 2023 21:13:59 +0200 Subject: Improve value casting infrastructure --- library/src/meta/reference.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'library/src/meta/reference.rs') 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( &self, vt: &mut Vt, - args: impl IntoIterator, + args: impl IntoIterator, ) -> SourceResult { 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 { -- cgit v1.2.3