From 9462fb17b390c57846b9215217ca7c32b649f0a5 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 16 Aug 2021 18:52:26 +0200 Subject: Convert single-field structs to tuple structs --- src/eval/function.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/eval/function.rs') diff --git a/src/eval/function.rs b/src/eval/function.rs index 85608ca1..7967090b 100644 --- a/src/eval/function.rs +++ b/src/eval/function.rs @@ -8,12 +8,10 @@ use crate::util::EcoString; /// An evaluatable function. #[derive(Clone)] -pub struct Function { - repr: Rc>, -} +pub struct Function(Rc>); -/// The unsized representation behind the [`Rc`]. -struct Repr { +/// The unsized structure behind the [`Rc`]. +struct Inner { name: Option, func: T, } @@ -26,17 +24,17 @@ impl Function { where F: Fn(&mut EvalContext, &mut Arguments) -> TypResult + 'static, { - Self { repr: Rc::new(Repr { name, func }) } + Self(Rc::new(Inner { name, func })) } /// The name of the function. pub fn name(&self) -> Option<&EcoString> { - self.repr.name.as_ref() + self.0.name.as_ref() } /// Call the function in the context with the arguments. pub fn call(&self, ctx: &mut EvalContext, args: &mut Arguments) -> TypResult { - (&self.repr.func)(ctx, args) + (&self.0.func)(ctx, args) } } @@ -53,14 +51,14 @@ impl Display for Function { impl Debug for Function { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - f.debug_struct("Function").field("name", &self.repr.name).finish() + f.debug_struct("Function").field("name", &self.0.name).finish() } } impl PartialEq for Function { fn eq(&self, other: &Self) -> bool { // We cast to thin pointers for comparison. - Rc::as_ptr(&self.repr) as *const () == Rc::as_ptr(&other.repr) as *const () + Rc::as_ptr(&self.0) as *const () == Rc::as_ptr(&other.0) as *const () } } -- cgit v1.2.3