From 1a390deaea040191cf0e5937bd8e1427b49db71b Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 11 Mar 2023 20:01:56 +0100 Subject: Figures --- src/eval/func.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/eval') diff --git a/src/eval/func.rs b/src/eval/func.rs index 8da5c6bc..26854240 100644 --- a/src/eval/func.rs +++ b/src/eval/func.rs @@ -142,6 +142,14 @@ impl Func { self.select(Some(fields)) } + /// The node id of this function if it is an element function. + pub fn id(&self) -> Option { + match **self.0 { + Repr::Node(id) => Some(id), + _ => None, + } + } + /// Execute the function's set rule and return the resulting style map. pub fn set(&self, mut args: Args) -> SourceResult { Ok(match &**self.0 { @@ -156,16 +164,15 @@ impl Func { /// Create a selector for this function's node type. pub fn select(&self, fields: Option) -> StrResult { - match **self.0 { - Repr::Node(id) => { - if id == item!(text_id) { - Err("to select text, please use a string or regex instead")?; - } + let Some(id) = self.id() else { + return Err("this function is not selectable".into()); + }; - Ok(Selector::Node(id, fields)) - } - _ => Err("this function is not selectable")?, + if id == item!(text_id) { + Err("to select text, please use a string or regex instead")?; } + + Ok(Selector::Node(id, fields)) } } @@ -196,10 +203,6 @@ impl From for Func { } } -cast_to_value! { - v: NodeId => Value::Func(v.into()) -} - /// A native Rust function. pub struct NativeFunc { /// The function's implementation. -- cgit v1.2.3