tinymist_std::typst::foundations

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 for T (for documentation and autocomplete).
  • IntoValue for T is for conversion from T -> Value (infallible)
  • FromValue for T is for conversion from Value -> 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§

fn input() -> CastInfo

Describe what can be cast into this value.

fn output() -> CastInfo

Describe what this value can be cast into.

fn castable(value: &Value) -> bool

Whether the given value can be converted to T.

This exists for performance. The check could also be done through the CastInfo, but it would be much more expensive (heap allocation + dynamic checks instead of optimized machine code for each type).

Provided Methods§

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.

Implementations on Foreign Types§

§

impl Reflect for bool

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for char

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for f64

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for i8

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for i16

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for i32

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for i64

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for isize

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for u8

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for u16

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for u32

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for u64

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for ()

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for usize

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for String

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for NonZero<i64>

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for NonZero<isize>

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for NonZero<u64>

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for NonZero<usize>

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for MathClass

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl Reflect for Month

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl<T> Reflect for Option<T>
where T: Reflect,

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl<T> Reflect for Result<T, HintedString>
where T: Reflect,

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl<T> Reflect for Result<T, EcoString>
where T: Reflect,

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl<T> Reflect for Result<T, EcoVec<SourceDiagnostic>>
where T: Reflect,

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl<T> Reflect for &T
where T: Reflect,

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl<T> Reflect for &mut T
where T: Reflect,

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl<T> Reflect for Arc<T>
where T: Reflect,

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

fn error(found: &Value) -> HintedString

§

impl<T> Reflect for Vec<T>

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl<T> Reflect for Spanned<T>
where T: Reflect,

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

§

impl<T, const N: usize> Reflect for SmallVec<[T; N]>
where T: Reflect,

§

fn input() -> CastInfo

§

fn output() -> CastInfo

§

fn castable(value: &Value) -> bool

Implementors§

§

impl Reflect for Datetime

§

impl Reflect for AngleLike

§

impl Reflect for DecNum

§

impl Reflect for Num

§

impl Reflect for ArgumentKey

§

impl Reflect for Endianness

§

impl Reflect for Never

§

impl Reflect for Replacement

§

impl Reflect for Selector

§

impl Reflect for StrPattern

§

impl Reflect for StrSide

§

impl Reflect for Target

§

impl Reflect for ToDecimal

§

impl Reflect for ToStr

§

impl Reflect for Transformation

§

impl Reflect for Value

§

impl Reflect for VersionComponents

§

impl Reflect for EcoString

§

impl Reflect for Bytes

§

impl Reflect for Dict

§

impl Reflect for ToAbs

§

impl Reflect for Args

§

impl Reflect for Array

§

impl Reflect for AutoValue

§

impl Reflect for Content

§

impl Reflect for Decimal

§

impl Reflect for DisplayPattern

§

impl Reflect for Duration

§

impl Reflect for Element

§

impl Reflect for Func

§

impl Reflect for Label

§

impl Reflect for LocatableSelector

§

impl Reflect for Module

§

impl Reflect for NoneValue

§

impl Reflect for PluginFunc

§

impl Reflect for Regex

§

impl Reflect for ShowableSelector

§

impl Reflect for Str

§

impl Reflect for Styles

§

impl Reflect for Symbol

§

impl Reflect for SymbolVariant

§

impl Reflect for ToArray

§

impl Reflect for ToBytes

§

impl Reflect for ToDict

§

impl Reflect for ToFloat

§

impl Reflect for ToInt

§

impl Reflect for Type

§

impl Reflect for Version

§

impl Reflect for Accent

§

impl Reflect for Alignment

§

impl Reflect for Angle

§

impl Reflect for Attribution

§

impl Reflect for Augment

§

impl Reflect for AugmentOffsets

§

impl Reflect for Author

§

impl Reflect for Axes<Length>

§

impl Reflect for Axes<Ratio>

§

impl Reflect for Axes<Rel>

§

impl Reflect for Axis

§

impl Reflect for Binding

§

impl Reflect for BlockBody

§

impl Reflect for BottomEdge

§

impl Reflect for BottomEdgeMetric

§

impl Reflect for CancelAngle

§

impl Reflect for Case

§

impl Reflect for Caseable

§

impl Reflect for ChromaComponent

§

impl Reflect for CitationForm

§

impl Reflect for CiteElem

§

impl Reflect for CloseMode

§

impl Reflect for Color

§

impl Reflect for ColorSpace

§

impl Reflect for Component

§

impl Reflect for Costs

§

impl Reflect for Counter

§

impl Reflect for CounterKey

§

impl Reflect for CounterState

§

impl Reflect for CounterUpdate

§

impl Reflect for Covers

§

impl Reflect for CslSource

§

impl Reflect for CurveComponent

§

impl Reflect for DashLength

§

impl Reflect for DashPattern

§

impl Reflect for DataSource

§

impl Reflect for Delimiter

§

impl Reflect for Delimiter

§

impl Reflect for DelimiterPair

§

impl Reflect for Destination

§

impl Reflect for Dir

§

impl Reflect for EmbeddedFileRelationship

§

impl Reflect for Encoding

§

impl Reflect for EnumItem

§

impl Reflect for EvalMode

§

impl Reflect for ExchangeFormat

§

impl Reflect for FigureCaption

§

impl Reflect for FigureKind

§

impl Reflect for FillRule

§

impl Reflect for FirstLineIndent

§

impl Reflect for FontFamily

§

impl Reflect for FontFeatures

§

impl Reflect for FontList

§

impl Reflect for FontStretch

§

impl Reflect for FontStyle

§

impl Reflect for FontWeight

§

impl Reflect for FootnoteBody

§

impl Reflect for FootnoteElem

§

impl Reflect for Fr

§

impl Reflect for Gradient

§

impl Reflect for GradientStop

§

impl Reflect for GridCell

§

impl Reflect for GridChild

§

impl Reflect for GridItem

§

impl Reflect for HAlignment

§

impl Reflect for HtmlAttr

§

impl Reflect for HtmlAttrs

§

impl Reflect for HtmlTag

§

impl Reflect for ImageFit

§

impl Reflect for ImageFormat

§

impl Reflect for ImageScaling

§

impl Reflect for Keywords

§

impl Reflect for Lang

§

impl Reflect for Length

§

impl Reflect for LineCap

§

impl Reflect for LineJoin

§

impl Reflect for LineNumberingScope

§

impl Reflect for Linebreaks

§

impl Reflect for LinkTarget

§

impl Reflect for ListItem

§

impl Reflect for ListMarker

§

impl Reflect for Location

§

impl Reflect for Margin

§

impl Reflect for Marginal

§

impl Reflect for MathSize

§

impl Reflect for MathVariant

§

impl Reflect for NumberType

§

impl Reflect for NumberWidth

§

impl Reflect for Numbering

§

impl Reflect for NumberingPattern

§

impl Reflect for OuterHAlignment

§

impl Reflect for OuterVAlignment

§

impl Reflect for OutlineEntry

§

impl Reflect for OutlineIndent

§

impl Reflect for Paint

§

impl Reflect for Paper

§

impl Reflect for Parity

§

impl Reflect for PathVertex

§

impl Reflect for PixelEncoding

§

impl Reflect for PixelFormat

§

impl Reflect for PlacementScope

§

impl Reflect for Position

§

impl Reflect for RasterFormat

§

impl Reflect for Ratio

§

impl Reflect for RatioComponent

§

impl Reflect for RatioOrAngle

§

impl Reflect for RawContent

§

impl Reflect for Readable

§

impl Reflect for RefForm

§

impl Reflect for Region

§

impl Reflect for Rel

§

impl Reflect for RelativeTo

§

impl Reflect for RowType

§

impl Reflect for ScaleAmount

§

impl Reflect for Side

§

impl Reflect for Sizing

§

impl Reflect for SmartQuoteDict

§

impl Reflect for SmartQuoteSet

§

impl Reflect for Spacing

§

impl Reflect for StackChild

§

impl Reflect for State

§

impl Reflect for StateUpdate

§

impl Reflect for Stroke

§

impl Reflect for StylisticSets

§

impl Reflect for Supplement

§

impl Reflect for TableCell

§

impl Reflect for TableChild

§

impl Reflect for TableItem

§

impl Reflect for TermItem

§

impl Reflect for TextDir

§

impl Reflect for TextSize

§

impl Reflect for Tiling

§

impl Reflect for TopEdge

§

impl Reflect for TopEdgeMetric

§

impl Reflect for TrackSizings

§

impl Reflect for Url

§

impl Reflect for VAlignment

§

impl Reflect for VElem

§

impl Reflect for VectorFormat

§

impl Reflect for VerticalFontMetric

§

impl Reflect for WeightedColor

§

impl Reflect for WritingScript

§

impl<H, V> Reflect for SpecificAlignment<H, V>
where H: Reflect, V: Reflect,

§

impl<S, D> Reflect for Derived<S, D>
where S: Reflect,

§

impl<T> Reflect for Smart<T>
where T: Reflect,

§

impl<T> Reflect for OneOrMultiple<T>
where T: Reflect,

§

impl<T> Reflect for Packed<T>

§

impl<T> Reflect for Celled<T>
where T: Reflect,

§

impl<T> Reflect for Corners<Option<T>>
where T: Reflect,

§

impl<T> Reflect for Sides<Option<T>>
where T: Reflect,