Expand description
§FastSerial
fastserial is a high-performance, format-agnostic serialization framework for Rust.
It is designed for high-throughput use cases by leveraging specialized code generation
and SIMD-accelerated scanning.
§Performance Highlights
- Encode: 1.3x - 2.0x faster than serde_json (depending on data structure)
- Decode: Optimized with binary search and SIMD scanning
- Memory: Zero-copy deserialization for borrowed types (
&str,&[u8])
§Design Goals
- High Performance: Maximum throughput in JSON and Binary formats.
- Zero-Copy: Borrowed data types are deserialized without allocation.
- SIMD Acceleration: First-class support for AVX2 and SSE4.2 instructions.
- Safety First: While leveraging
unsafefor SIMD, the public API remains safe. - Minimal Overhead: Thin abstraction layer that compiles to efficient machine code.
§Supported Formats
| Format | Module | Description |
|---|---|---|
| JSON | json | High-speed JSON with SIMD scanning. |
| Binary | binary | Compact, schema-validated binary format. |
§Core Traits
There are two primary traits that power fastserial:
Encode: Types that can be serialized into a supported format.Decode: Types that can be deserialized from a byte buffer.
For most users, these traits should be implemented using the derive macros:
use fastserial::{Encode, Decode, json};
#[derive(Encode, Decode, Debug, PartialEq)]
struct User {
id: u64,
username: String,
email: String,
}
let user = User {
id: 42,
username: "dev_user".to_string(),
email: "dev@example.com".to_string(),
};
// Serialize to JSON string
let json_data = json::encode(&user)?;
// Deserialize back to struct
let decoded: User = json::decode(&json_data)?;
assert_eq!(user, decoded);§SIMD Support and Safety
fastserial automatically detects CPU features at runtime to use the fastest possible
implementation.
- AVX2: Used on modern x86_64 CPUs for 32-byte parallel scanning.
- SSE4.2: Fallback for older x86_64 CPUs.
- NEON: ARM-specific SIMD for mobile and embedded devices.
- Scalar: Default implementation for other architectures or when SIMD is disabled.
All unsafe code used for SIMD is encapsulated within the simd module and is
thoroughly tested for memory safety.
§Feature Flags
std(default): Enables support forstdtypes likeString,Vec, andstd::error::Error.json(default): Enables JSON serialization/deserialization.binary(default): Enables FastSerial binary format.chrono: Enables serialization support forchronodate/time types.profile: Enables internal profiling for performance debugging.
§Quick Start
use fastserial::{Encode, Decode, json};
#[derive(Encode, Decode, Debug)]
struct Point {
x: i32,
y: i32,
}
let p = Point { x: 10, y: 20 };
let encoded = json::encode(&p)?;
let decoded: Point = json::decode(&encoded)?;
assert_eq!(p.x, decoded.x);Re-exports§
pub use value::Value;
Modules§
- binary
- FastSerial binary format support.
- codec
- Codec implementations for various formats (JSON, Binary, etc.)
- io
- I/O traits and buffers for reading and writing.
- json
- JSON format support.
- msgpack
- schema
- Schema hashing and validation.
- simd
- SIMD-accelerated low-level operations.
- value
Enums§
- Error
- Error types for serialization and deserialization operations.
Traits§
- Decode
- Trait for types that can be decoded from a byte buffer.
- Encode
- Trait for types that can be encoded into a format.
- Format
- Trait for implementing custom serialization formats.