#dynamic #value #json

no-std facet-value

Memory-efficient dynamic value type for facet, supporting JSON-like data plus bytes

23 releases (10 breaking)

Uses new Rust 2024

new 0.46.0 Apr 15, 2026
0.44.5 Mar 16, 2026
0.41.0 Dec 31, 2025

#716 in Encoding

Download history 22/week @ 2025-12-28 52/week @ 2026-01-04 90/week @ 2026-01-11 134/week @ 2026-01-18 191/week @ 2026-01-25 137/week @ 2026-02-01 55/week @ 2026-02-08 42/week @ 2026-02-15 77/week @ 2026-02-22 414/week @ 2026-03-01 236/week @ 2026-03-08 400/week @ 2026-03-15 468/week @ 2026-03-22 653/week @ 2026-03-29 394/week @ 2026-04-05 486/week @ 2026-04-12

2,031 downloads per month
Used in 64 crates (14 directly)

MIT/Apache

745KB
16K SLoC

facet-value

Coverage Status crates.io documentation MIT/Apache-2.0 licensed Discord

facet-value provides a memory-efficient dynamic value type for representing structured data similar to JSON, but with added support for binary data and datetime.

Features

  • Pointer-sized Value type: The main Value type is exactly one pointer in size
  • Eight value types: Null, Bool, Number, String, Bytes, Array, Object, DateTime
  • no_std compatible: Works with just alloc, no standard library required
  • Bytes support: First-class support for binary data (useful for MessagePack, CBOR, etc.)
  • DateTime support: First-class support for temporal data (useful for TOML, YAML, etc.)

Design

Value uses a tagged pointer representation with 8-byte alignment, giving us 3 tag bits to distinguish between value types. Inline values (null, true, false) don’t require heap allocation.

facet-value

A memory-efficient dynamic value type for representing structured data, with support for bytes.

Features

  • Pointer-sized: Value is exactly one pointer in size using tagged pointers
  • Rich type support: Null, Bool, Number, String, Bytes, Array, Object, DateTime
  • Typed extraction: Convert from Value into any type implementing Facet
  • Companion serializer: Use facet-format to serialize typed values into Value

Example

use facet::Facet;
use facet_value::{Value, from_value};
use facet_format::to_value;

#[derive(Debug, Facet, PartialEq)]
struct Person {
    name: String,
    age: u32,
}

// Convert a typed value to a dynamic Value
let person = Person { name: "Alice".into(), age: 30 };
let value: Value = to_value(&person).unwrap();

// Inspect the value dynamically
let obj = value.as_object().unwrap();
assert_eq!(obj.get("name").unwrap().as_string().unwrap().as_str(), "Alice");

// Convert back to a typed value
let person2: Person = from_value(value).unwrap();
assert_eq!(person, person2);

Sponsors

Thanks to all individual sponsors:

GitHub Sponsors Patreon

...along with corporate sponsors:

AWS Zed Depot

...without whom this work could not exist.

Special thanks

The facet logo was drawn by Misiasart.

License

Licensed under either of:

at your option.

Dependencies

~3MB
~56K SLoC