Trait Reflect
pub trait Reflect {
// Required methods
fn input() -> CastInfo;
fn output() -> CastInfo;
fn castable(value: &Value) -> bool;
// Provided method
fn error(found: &Value) -> HintedString { ... }
}
Expand description
Determine details of a type.
Type casting works as follows:
Reflect for T
describes the possible Typst values forT
(for documentation and autocomplete).IntoValue for T
is for conversion fromT -> Value
(infallible)FromValue for T
is for conversion fromValue -> T
(fallible).
We can’t use TryFrom<Value>
due to conflicting impls. We could use
From<T> for Value
, but that inverses the impl and leads to tons of
.into()
all over the place that become hard to decipher.
Required Methods§
Provided Methods§
fn error(found: &Value) -> HintedString
fn error(found: &Value) -> HintedString
Produce an error message for an unacceptable value type.
ⓘ
assert_eq!(
<i64 as Reflect>::error(&Value::None),
"expected integer, found none",
);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.