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::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;

Modules§

complex
Complex number primitives suitable as element types of NumericArray and PackedArray.
constants
WXF wire-format constants and enums.
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.
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.

Structs§

SliceReader
Slice-backed Reader: holds &[u8] plus a position. Every read is a bounds-checked sub-slice — no allocation, no copy.
WxfReader
Typed WXF reader wrapping a raw byte Reader.
WxfWriter
Typed WXF writer wrapping a raw byte Writer.

Enums§

CompressionLevel
zlib compression level passed to to_wxf.
Error
Errors returned by to_wxf / from_wxf and every ToWXF / FromWXF impl.

Traits§

Reader
Raw byte source that lends buffer-lifetime views. 'de is the lifetime of the underlying buffer. Reads consume forward; there is no rewind, no peek.
ToWXF
Types that know how to serialize themselves into a WXF stream.
Writer
Raw byte sink.
WxfStruct
Marker auto-implemented by #[derive(ToWXF)] for user structs/enums. Gates the blanket impl ToWXF for Vec<T> (List form) so it can’t conflict with the numeric-primitive Vec specializations.

Functions§

from_wxf
Deserialize bytes (WXF; 8: or 8C: auto-detected) into a typed T.
read_wxf
Strip the WXF header (8: / 8C: auto-detected, decompressing if needed) and hand the closure a WxfReader positioned at the start of the token stream, so it can drive the cursor directly.
to_wxf
Serialize value to WXF.

Derive Macros§

Failure
Derive From<YourEnum> for Expr, mapping each variant to a Wolfram Failure expression.
FromWXF
Derive FromWXF for a struct or enum.
ToWXF
Derive ToWXF for a struct or enum.