| Crates.io | typwire |
| lib.rs | typwire |
| version | 0.1.0 |
| created_at | 2025-12-15 22:04:48.89391+00 |
| updated_at | 2025-12-15 22:04:48.89391+00 |
| description | Rust types for the Typst plugin system. |
| homepage | |
| repository | https://github.com/T1mVo/typwire |
| max_upload_size | |
| id | 1986833 |
| size | 78,750 |
An extended CBOR encoder for the Typst plugin system.
This library provides a CBOR encoder with extended support for Typst types, along with corresponding Rust types and deserialization, enabling seamless data exchange between Typst and Rust WASM plugins.
Note: The versions used in Typst and Rust MUST match exactly.
Rust:
Add typwire to your Rust project like this:
cargo add typwire
use serde::Deserialize;
use typwire::{Angle, Color, DateTime, FromBytes as _};
use wasm_minimal_protocol::*;
initiate_protocol!();
#[derive(Deserialize)]
struct Custom {
angle: Angle,
color: Color,
datetime: DateTime,
}
#[wasm_func]
fn custom_fn(arg: &[u8]) -> Result<Vec<u8>, String> {
let custom = Custom::from_bytes(arg)?;
// ...
Ok(vec![])
}
Typst:
#import "@preview/typwire:0.1.0"
#let custom-plugin = plugin("custom_plugin.wasm")
#let custom = (
"angle": 90deg,
"color": red,
"datetime": datetime.today(),
)
#let encoded = typwire.cbor.encode(custom)
#custom-plugin.custom_fn(encoded)