Skip to main content

Crate fastserial

Crate fastserial 

Source
Expand description

§FastSerial

fastserial is a high-performance, format-agnostic serialization framework for Rust. It is an ambitious project designed for specific high-throughput use cases by leveraging specialized code generation and SIMD-accelerated scanning.

§Design Goals

  • High Performance: Aiming for maximum throughput in JSON and Binary formats.
  • Zero-Copy: Borrowed data types (like &str and &[u8]) are deserialized without allocation.
  • SIMD Acceleration: First-class support for AVX2 and SSE4.2 instructions for JSON parsing.
  • Safety First: While leveraging unsafe for SIMD, the public API remains completely safe.
  • Minimal Overhead: Thin abstraction layer that compiles down to efficient machine code.

§Supported Formats

FormatModuleDescription
JSONjsonHigh-speed JSON with SIMD scanning.
BinarybinaryCompact, schema-validated binary format.

§Core Traits

There are two primary traits that power fastserial:

  1. Encode: Types that can be serialized into a supported format.
  2. 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.
  • 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 for std types like String, Vec, and std::error::Error.
  • json (default): Enables JSON serialization/deserialization.
  • binary (default): Enables FastSerial binary format.
  • chrono: Enables serialization support for chrono date/time types.
  • profile: Enables internal profiling for performance debugging.

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.
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.

Derive Macros§

Decode
Derive macro for the Decode trait.
Encode
Derive macro for the Encode trait.