Skip to main content

ToDict

Trait ToDict 

Source
pub trait ToDict {
    // Required method
    fn into_dict(self) -> Dict;
}
Expand description

Converts a Rust struct into a Typst Dict.

Derive it with #[derive(ToDict)] (see the ToDict macro), which also implements ToValue by wrapping the dict, so derived types can nest.

use typst_template::{ToDict, ToValue, Value};

#[derive(ToDict)]
struct Point {
    x: i64,
    y: i64,
}

let dict = Point { x: 1, y: 2 }.into_dict();
assert_eq!(dict.get("x").unwrap(), &Value::Int(1));

Required Methods§

Source

fn into_dict(self) -> Dict

Consumes self and produces the Typst dictionary.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ToDict for Map<String, Value>

Available on crate feature serde_json only.
Source§

impl<K: Into<Str>, V: ToValue, S> ToDict for HashMap<K, V, S>

Source§

impl<K: Into<Str>, V: ToValue> ToDict for BTreeMap<K, V>

Implementors§