ランキングに戻る

facet-rs/facet

Rustfacet.rs

Rust reflection, serialization, deserialization, pretty printing, etc. — the last proc macro you should need

deserializationrustrust-langserializationdebuggingintrospectionreflection
スター成長
スター
2.6k
フォーク
124
週間成長
Issue
138
1k2k
2025年3月2025年8月2026年2月2026年7月
成果物crates.iocargo add facet
README

facet

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

facet is an entire ecosystem of Rust crates built on top of reflection.

The core facet crates give types a SHAPE associated const with details on the kind (struct, enum, tuple?), layout (size, alignment), fields, doc comments, arbitrary attributes, along with

From there, facet-reflect allows reading from existing values, building new values from scratch, and even mutating existing values in-place if they're plain old data.

A rich (de)serialization ecosystem is built on top of these, for formats like JSON, TOML, YAML, MsgPack, Postcard, ASN1, XDR, CSV, XML, but also facet-native (ie. designed by the same authors and leveraging some capabilities that would be hard to get elsewhere) like styx (a human-oriented document language you'd use in place of YAML or TOML) and phon (a schema-aware binary format that comes in self-describing form and in compact form).

Inserting or fetching records from database is essentially (de)serialization again, so the facet ecosystem also includes adapters for sqlite and Postgres (via dibs, which does a little more than just data binding).

Want two programs to talk to each other? vox has you covered: an RPC system built on top of the Phon binary format, which purports to support forwards and backwards compatibility, although nobody's built the "semver checks" tooling for it yet so, PRs welcome.

Reflection has a cost: facet-json used to be 5-7x slower than serde-json. In comes weavy, an IR target that any crate can lower to, using their own intrinsics, for which they can provide native stencils. On platforms that support it, weavy uses a copy-patch technique to assemble native code for much faster (citation needed) execution still. Not an option on iPhone, and generally a memory safety liability.

For syntax highlighting, I (Amos) was a bit annoyed that arborium (a tree-sitter grammar distribution) required a C toolchain, so I made snark, a tree-sitter-compatible parser framework, which lowers to weavy, has JIT support, and will happily codegen an AST for you (into which it can parse your language) given a few extra annotations.

Website note

The https://facet.rs website has a lot of information about a lot of the ecosystem but it's unfortunately not super reliable as LLMs have been doing too much of the writing (on account on Amos being burned out). This is being slowly repaired. Bear with us.

Workspace contents

The main facet crate re-exports symbols from:

  • facet-core, which defines the main components:
    • The [Facet] trait and implementations for foreign types (mostly libstd)
    • The [Shape] struct along with various vtables and the whole [Def] tree
    • Type-erased pointer helpers like [PtrUninit], [PtrConst], and [Opaque]
    • Autoderef specialization trick needed for facet-macros
  • facet-macros, which implements the [Facet] derive attribute as a fast/light proc macro powered by unsynn

For struct manipulation and reflection, we have:

  • facet-reflect, allows building values of arbitrary shapes in safe code, respecting invariants. It also allows peeking at existing values.

Internal crates include:

  • facet-testhelpers a simple log logger and color-backtrace configured with the lightweight btparse backend

Ecosystem

Various crates live under the https://github.com/facet-rs umbrella, and their repositories are kept somewhat-consistent through facet-dev.

Crates are in various states of progress, buyer beware!

In terms of data formats, we have:

Still adjacent to serialization/deserialization, we have:

  • facet-urlencoded: URL-encoded form data deserialization
  • figue: CLI arguments, config files, and environment variables (external crate)

As far as utilities go:

And the less developed:

  • facet-inspect: Utilities to inspect the content of a Facet object

Previously separate crates

These crates previously lived in separate repositories and now live in this monorepo:

  • facet-xml: XML/DOM ecosystem (includes facet-xml, facet-dom, facet-svg, facet-atom, facet-xml-node, facet-singularize)
  • facet-axum: Axum web framework integration

Extended cinematic universe

Some crates are developed completely independently from the facet org:

  • facet-v8 provides an experimental Facet/v8 integration
  • facet-openapi (experimental) Generates OpenAPI definitions from types that implement Facet
  • facet_generate reflects Facet types into Java, Swift and TypeScript
  • multi-array-list provides an experimental MultiArrayList type

Sponsors

Thanks to all individual sponsors:

GitHub Sponsors Patreon

...without whom this work could not exist.

Special thanks

The facet logo was drawn by Misiasart.

License

Licensed under either of:

at your option.

関連リポジトリ
alibaba/fastjson

FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.

JavaMavenApache License 2.0fastjsonjava
github.com/alibaba/fastjson2/wiki/fastjson_1_upgrade_cn
25.6k6.4k
json-iterator/go

A high-performance 100% compatible drop-in replacement of "encoding/json"

GoGo ModulesMIT Licensegogolang
jsoniter.com/migrate-from-go-std.html
13.9k1.1k
frohoff/ysoserial

A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.

JavaMavenMIT Licensejavadeserialization
frohoff.github.io/appseccali-marshalling-pickles/
9k1.9k
ijl/orjson

Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy

PythonPyPIApache License 2.0jsonpython
8.2k315
marshmallow-code/marshmallow

A lightweight library for converting complex objects to and from simple Python datatypes.

PythonPyPIMIT Licenseserializationdeserialization
marshmallow.readthedocs.io
7.2k712
alibaba/fastjson2

🚄 FASTJSON2 is a Java JSON library with excellent performance.

JavaMavenApache License 2.0jsonfastjson
4.3k574
alibaba/HandyJSON

A handy swift json-object serialization/deserialization library

SwiftOtherswiftjson
4.3k676
msgspec/msgspec

A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML

PythonPyPIBSD 3-Clause "New" or "Revised" Licensemsgpackserialization
msgspec.dev
3.9k161
ibireme/yyjson

The fastest JSON library in C

CMIT Licensejsonc
ibireme.github.io/yyjson/doc/doxygen/html/
3.8k334
jcrist/msgspec

A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML

PythonPyPIBSD 3-Clause "New" or "Revised" Licensemsgpackserialization
jcristharif.com/msgspec/
2.6k89
schematics/schematics

Python Data Structures for Humans™.

PythonPyPIOtherpythonvalidation
schematics.readthedocs.org
2.6k293
joaomatosf/jexboss

JexBoss: Jboss (and Java Deserialization Vulnerabilities) verify and EXploitation Tool

PythonPyPIOtherexploitexploiting-vulnerabilities
2.5k641