Skip to main content

Crate wolfram_serialize

Crate wolfram_serialize 

Source
Expand description

Serialize and deserialize Wolfram Language expressions to and from the WXF binary wire format.

Two layers:

  • Byte level — Reader / Writer. Reader lends zero-copy buffer-lifetime views (&'de), so the default SliceReader reads straight out of an in-memory buffer; the default writer is Vec<u8>.
  • WXF level — WxfReader / WxfWriter, typed sugar over the byte layer built on the WXF token enums.

Per-Rust-type encoding/decoding is ToWXF / FromWXF, both generic over the byte layer (monomorphized, no dyn, streaming). Top-level entry points: [to_wxf] (compression optional), [from_wxf], read_wxf.

Re-exports§

pub use crate::errors::Error;
pub use crate::complex::Complex;
pub use crate::complex::Complex32;
pub use crate::complex::Complex64;
pub use crate::constants::ExpressionEnum;
pub use crate::constants::HeaderEnum;
pub use crate::constants::NumericArrayEnum;
pub use crate::constants::PackedArrayEnum;
pub use crate::from_wxf::FromWXF;
pub use crate::reader::Reader;
pub use crate::reader::SliceReader;
pub use crate::to_wxf::ToWXF;
pub use crate::to_wxf::WxfStruct;
pub use crate::writer::Writer;
pub use crate::wxf::reader::WxfReader;
pub use crate::wxf::writer::WxfWriter;

Modules§

complex
Complex number primitives suitable as element types of NumericArray and [PackedArray][crate::PackedArray].
constants
WXF wire-format constants and enums.
errors
The crate-wide WXF error type.
from_wxf
FromWXF — pull-based typed deserialization from a WxfReader.
numeric_in
Flexible numeric-input helpers — accept any of NumericArray, PackedArray, or ByteArray on the wire and widen the element type into the caller’s target T. The widening rules are lossless: a source type is accepted only when every value of its domain is exactly representable in the target.
reader
Minimal byte-level reader.
strategy
Encoding strategies — the conventions for mapping Rust shapes onto WXF expressions. These sit a layer above the cursor (WxfReader/WxfWriter, which only know raw WXF tokens) and are shared by the #[derive] codegen and the hand-written std impls (Option, Result, …) so the wire format lives in exactly one place.
to_wxf
ToWXF — per-Rust-type WXF encoder. Streams directly into a WxfWriter: compounds write a header then recurse into children. No intermediate Vec, no &dyn dispatch — fully monomorphized.
writer
Minimal byte-level writer.
wxf
WXF binary wire format — typed WxfReader / WxfWriter. Header framing (8: / 8C:) is handled by [crate::wxf_payload].

Enums§

CompressionLevel
zlib compression level passed to [to_wxf].

Functions§

from_wxf
Deserialize bytes (WXF; 8: or 8C: auto-detected) into a typed T.
from_wxf_ref
Deserialize bytes into a borrowed T whose &str / &[u8] fields point straight into bytes (zero-copy). The result borrows bytes, so the input must be uncompressed (8:) — a 8C: payload would have to be decompressed into a temporary the borrow couldn’t outlive (use [from_wxf] for the owned form, or read_wxf to borrow within a closure).
read_wxf
Read from a WXF blob (8: / 8C: auto-detected) via a WxfReader. The closure can pull one or more top-level values — e.g. a Function[List, …] wrapper around several arguments. For a single value, prefer [from_wxf].
to_wxf
Serialize value to WXF.

Derive Macros§

Failure
Derive From<Enum> for Expr for an error enum: each variant becomes its Failure["VariantName", <|fields|>] expression (the expr! boilerplate one would otherwise write by hand, inferred from the enum).
FromWXF
Derive FromWXF for a struct or enum.
ToWXF
Derive ToWXF for a struct or enum.