Expand description
Serde Integration for StructFS
This layer provides typed access to StructFS stores via serde. It adds:
TypedReader: Read directly into Rust typesTypedWriter: Write Rust types directlyJsonCodec: A codec for JSON format- Value <-> serde conversions
§Lossless values
use structfs_serde_store::{Codec, Format, Value, ValueJsonCodec};
let value = Value::Array(vec![Value::from(u64::MAX), Value::Bytes(vec![0, 255])]);
let bytes = ValueJsonCodec.encode(&value, &Format::VALUE_JSON)?;
let decoded = ValueJsonCodec.decode(&bytes, &Format::VALUE_JSON)?;
assert!(value.semantic_eq(&decoded));Plain JSON rejects bytes and non-finite floats. Use ValueCodec to select
a profile and Limits explicitly. to_value and from_value use the
structural Serde mapping directly; ambiguous null-valued options require
ExplicitOption. All codecs validate complete documents. Raw record
forwarding does not imply validation; use transcode for that contract.
§Example
ⓘ
use structfs_serde_store::{TypedReader, TypedWriter, JsonCodec};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct User {
name: String,
age: u32,
}
fn read_user(store: &mut dyn Reader) -> Result<Option<User>, Error> {
let codec = JsonCodec;
store.read_as(&path!("users/123"), &codec)
}§Async Support
Enable the async feature for async trait variants:
[dependencies]
structfs-serde-store = { version = "0.1", features = ["async"] }Then use AsyncTypedReader and AsyncTypedWriter.
Structs§
- Bytes
- A cheaply cloneable and sliceable chunk of contiguous memory.
- Cbor
Codec - StructFS CBOR v1 with default limits.
- Explicit
Option - Schema-visible option that can preserve Some(()) and nested optional states.
- Flexbuffers
Codec - StructFS FlexBuffers v1 with default limits; NUL map keys fail.
- Format
- A hint about the wire format of raw bytes.
- Json
Codec - Strict plain JSON with default limits; bytes and non-finite floats fail.
- Limits
- Inclusive bounds. Work counts traversed nodes and bytes, plus collection sorting estimates. Allocation counts conservative reservations, not allocator metadata.
- Multi
Codec - A codec that combines multiple codecs.
- Path
- A validated path in StructFS.
- Value
Codec - A codec with caller-configured finite limits. Canonical validation applies only to tagged JSON and compares the complete supplied document, including whitespace.
- Value
Json Codec - Lossless canonical StructFS Value JSON v1 with default limits.
Enums§
- Error
- Errors at the Core layer.
- Path
Error - Errors related to path parsing and validation.
- Profile
- Explicitly selected StructFS v1 codec contract.
- Record
- A record that can be forwarded without parsing or parsed for inspection.
- Value
- A tree-shaped value that can be read from or written to a Store.
Traits§
- Codec
- Codec for converting between Value and bytes.
- Reader
- Read records from paths.
- Store
- Combined read/write at the Core level.
- Typed
Reader - Extension trait for typed reads.
- Typed
Writer - Extension trait for typed writes.
- Writer
- Write records to paths.
Functions§
- from_
value - from_
value_ with_ limits - json_
to_ value - Import an already parsed JSON DOM, preserving its exact supported numbers.
- to_
value - to_
value_ with_ limits - transcode
- Validate and transcode a document, even when both profiles are the same. Raw byte forwarding is deliberately a different operation.
- validate_
value - Validate an existing value before traversing or cloning it at a trust boundary.
- value_
to_ json - Convert to plain JSON, rejecting bytes and non-finite floats.