diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-08-16 18:52:26 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-08-16 19:15:03 +0200 |
| commit | 9462fb17b390c57846b9215217ca7c32b649f0a5 (patch) | |
| tree | bd6f96fea83c5e757c8f0eefefe5c0347784f00b /src/eval/function.rs | |
| parent | cb0aab3cfab2122a87d1d221290f7178b4291758 (diff) | |
Convert single-field structs to tuple structs
Diffstat (limited to 'src/eval/function.rs')
| -rw-r--r-- | src/eval/function.rs | 18 |
1 files changed, 8 insertions, 10 deletions
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<Repr<Func>>, -} +pub struct Function(Rc<Inner<Func>>); -/// The unsized representation behind the [`Rc`]. -struct Repr<T: ?Sized> { +/// The unsized structure behind the [`Rc`]. +struct Inner<T: ?Sized> { name: Option<EcoString>, func: T, } @@ -26,17 +24,17 @@ impl Function { where F: Fn(&mut EvalContext, &mut Arguments) -> TypResult<Value> + '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<Value> { - (&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 () } } |
