pub trait ToValue {
// Required method
fn into_value(self) -> Value;
}Expand description
Converts a Rust value into a Typst Value.
This is the leaf conversion used by ToDict and by the
ToDict derive. It is implemented for the common
scalar, collection, and Typst value types; enable cargo features for
chrono, rust_decimal, serde_json, and uuid to convert those too.
use typst_template::{ToValue, Value};
assert_eq!(42_i64.into_value(), Value::Int(42));
assert_eq!(Some("hi").into_value(), Value::Str("hi".into()));
assert_eq!(Option::<i64>::None.into_value(), Value::None);Required Methods§
Sourcefn into_value(self) -> Value
fn into_value(self) -> Value
Consumes self and produces the Typst value.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl ToValue for Date
Available on crate feature time only.
impl ToValue for Date
Available on crate feature
time only.fn into_value(self) -> Value
Source§impl ToValue for Decimal
Available on crate feature rust_decimal only.
impl ToValue for Decimal
Available on crate feature
rust_decimal only.fn into_value(self) -> Value
Source§impl ToValue for Map<String, Value>
Available on crate feature serde_json only.
impl ToValue for Map<String, Value>
Available on crate feature
serde_json only.fn into_value(self) -> Value
Source§impl ToValue for NaiveDate
Available on crate feature chrono only.
impl ToValue for NaiveDate
Available on crate feature
chrono only.fn into_value(self) -> Value
Source§impl ToValue for NaiveDateTime
Available on crate feature chrono only.
impl ToValue for NaiveDateTime
Available on crate feature
chrono only.fn into_value(self) -> Value
Source§impl ToValue for NaiveTime
Available on crate feature chrono only.
impl ToValue for NaiveTime
Available on crate feature
chrono only.fn into_value(self) -> Value
Source§impl ToValue for OffsetDateTime
Available on crate feature time only.Uses the value’s own UTC offset.
impl ToValue for OffsetDateTime
Available on crate feature
time only.Uses the value’s own UTC offset.
fn into_value(self) -> Value
Source§impl ToValue for PrimitiveDateTime
Available on crate feature time only.
impl ToValue for PrimitiveDateTime
Available on crate feature
time only.fn into_value(self) -> Value
Source§impl ToValue for Time
Available on crate feature time only.
impl ToValue for Time
Available on crate feature
time only.fn into_value(self) -> Value
Source§impl ToValue for Uuid
Available on crate feature uuid only.
impl ToValue for Uuid
Available on crate feature
uuid only.fn into_value(self) -> Value
Source§impl ToValue for Value
Available on crate feature serde_json only.
impl ToValue for Value
Available on crate feature
serde_json only.fn into_value(self) -> Value
Source§impl<K: Into<Str>, V: ToValue, S> ToValue for HashMap<K, V, S>
impl<K: Into<Str>, V: ToValue, S> ToValue for HashMap<K, V, S>
fn into_value(self) -> Value
Source§impl<Tz: TimeZone> ToValue for DateTime<Tz>
Available on crate feature chrono only.Uses the value’s local wall-clock time.
impl<Tz: TimeZone> ToValue for DateTime<Tz>
Available on crate feature
chrono only.Uses the value’s local wall-clock time.