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 /src/model/element.rs | |
| parent | 168bdf35bd773e67343c965cb473492cc5cae9e7 (diff) | |
Improve value casting infrastructure
Diffstat (limited to 'src/model/element.rs')
| -rw-r--r-- | src/model/element.rs | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/src/model/element.rs b/src/model/element.rs index e26848b1..c673ee41 100644 --- a/src/model/element.rs +++ b/src/model/element.rs @@ -2,14 +2,11 @@ use std::any::TypeId; use std::fmt::{self, Debug, Formatter}; use std::hash::{Hash, Hasher}; -use ecow::EcoString; use once_cell::sync::Lazy; use super::{Content, Selector, Styles}; use crate::diag::SourceResult; -use crate::eval::{ - cast_from_value, cast_to_value, Args, Dict, Func, FuncInfo, Value, Vm, -}; +use crate::eval::{cast, Args, Dict, Func, FuncInfo, Value, Vm}; /// A document element. pub trait Element: Construct + Set + Sized + 'static { @@ -110,15 +107,12 @@ impl Hash for ElemFunc { } } -cast_from_value! { +cast! { ElemFunc, + self => Value::Func(self.into()), v: Func => v.element().ok_or("expected element function")?, } -cast_to_value! { - v: ElemFunc => Value::Func(v.into()) -} - impl From<&'static NativeElemFunc> for ElemFunc { fn from(native: &'static NativeElemFunc) -> Self { Self(native) @@ -138,22 +132,3 @@ pub struct NativeElemFunc { /// Details about the function. pub info: Lazy<FuncInfo>, } - -/// A label for an element. -#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] -pub struct Label(pub EcoString); - -impl Debug for Label { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "<{}>", self.0) - } -} - -/// Indicates that an element cannot be labelled. -pub trait Unlabellable {} - -/// Tries to extract the plain-text representation of the element. -pub trait PlainText { - /// Write this element's plain text into the given buffer. - fn plain_text(&self, text: &mut EcoString); -} |
