Skip to main content

Serializer

Trait Serializer 

Source
pub trait Serializer: 'static {
Show 20 methods // Required methods fn fory_write_data( &self, context: &mut WriteContext<'_>, ) -> Result<(), Error>; fn fory_read_data(context: &mut ReadContext<'_>) -> Result<Self, Error> where Self: Sized + ForyDefault; fn fory_type_id_dyn( &self, type_resolver: &TypeResolver, ) -> Result<TypeId, Error>; fn as_any(&self) -> &(dyn Any + 'static); // Provided methods fn fory_write( &self, context: &mut WriteContext<'_>, ref_mode: RefMode, write_type_info: bool, has_generics: bool, ) -> Result<(), Error> where Self: Sized { ... } fn fory_write_data_generic( &self, context: &mut WriteContext<'_>, has_generics: bool, ) -> Result<(), Error> { ... } fn fory_write_type_info(context: &mut WriteContext<'_>) -> Result<(), Error> where Self: Sized { ... } fn fory_read( context: &mut ReadContext<'_>, ref_mode: RefMode, read_type_info: bool, ) -> Result<Self, Error> where Self: Sized + ForyDefault { ... } fn fory_read_with_type_info( context: &mut ReadContext<'_>, ref_mode: RefMode, type_info: Rc<TypeInfo>, ) -> Result<Self, Error> where Self: Sized + ForyDefault { ... } fn fory_read_type_info(context: &mut ReadContext<'_>) -> Result<(), Error> where Self: Sized { ... } fn fory_is_option() -> bool where Self: Sized { ... } fn fory_is_none(&self) -> bool { ... } fn fory_is_polymorphic() -> bool where Self: Sized { ... } fn fory_is_shared_ref() -> bool where Self: Sized { ... } fn fory_is_wrapper_type() -> bool where Self: Sized { ... } fn fory_static_type_id() -> TypeId where Self: Sized { ... } fn fory_get_type_id(type_resolver: &TypeResolver) -> Result<TypeId, Error> where Self: Sized { ... } fn fory_get_type_info( type_resolver: &TypeResolver, ) -> Result<Rc<TypeInfo>, Error> where Self: Sized { ... } fn fory_concrete_type_id(&self) -> TypeId { ... } fn fory_reserved_space() -> usize where Self: Sized { ... }
}
Expand description

Core trait for Fory serialization and deserialization.

Serializer is the primary trait that enables types to be serialized and deserialized using Fory’s high-performance cross-language protocol. All types that can be serialized with Fory must implement this trait, either manually or via the #[derive(ForyObject)] macro.

§Architecture Overview

Fory’s serialization consists of three main phases:

  1. Reference tracking (optional): Writes/reads null/not-null/ref flags for handling shared references and circular references
  2. Type information (optional): Writes/reads type metadata for polymorphic types
  3. Data serialization: Writes/reads the actual data payload

§Method Categories

§Methods Users Must Implement (for custom serialization logic)

§Methods Implemented by Fory (override only if needed)

Most methods have default implementations suitable for common types:

§Type Query Methods

These provide compile-time and runtime type information:

§Typical Usage Pattern

For types that need custom serialization logic (EXT types), you only need to implement four methods:

impl Serializer for MyType {
    fn fory_write_data(&self, context: &mut WriteContext) -> Result<(), Error> {
        // Write your type's fields
    }

    fn fory_read_data(context: &mut ReadContext) -> Result<Self, Error> {
        // Read your type's fields
    }

    fn fory_type_id_dyn(&self, type_resolver: &TypeResolver) -> Result<fory_core::TypeId, Error> {
        Self::fory_get_type_id(type_resolver)
    }

    fn as_any(&self) -> &dyn Any {
        self
    }
}

§Derive Macro

For struct types, you can use the #[derive(ForyObject)] macro instead of implementing manually:

#[derive(ForyObject)]
struct Point {
    x: f64,
    y: f64,
}

§See Also

  • ForyDefault: Trait for creating default values during deserialization
  • StructSerializer: Extended trait for struct-specific serialization

Required Methods§

Source

fn fory_write_data(&self, context: &mut WriteContext<'_>) -> Result<(), Error>

[USER IMPLEMENTATION REQUIRED] Serialize the type’s data to the buffer.

This is the core serialization method that you must implement for custom types. It should write all the type’s fields and data to the buffer using the provided context.

§Parameters
  • context - Write context providing:
    • context.writer: Buffer to write binary data
    • context.type_resolver: Registry of type information
    • context.ref_resolver: Resolver for shared/circular references (if enabled)
§Writing Data

Use methods on context.writer to write primitive types:

  • write_i8(), write_i16(), write_i32(), write_i64(): Signed integers
  • write_u8(), write_u16(), write_u32(), write_u64(): Unsigned integers
  • write_f32(), write_f64(): Floating point numbers
  • write_bool(): Boolean values
  • write_bytes(): Raw byte arrays

For nested types that implement Serializer, call their serialization:

// For types that implement Serializer
self.nested_field.fory_write(context, false, false, false)?;
§Examples
§Simple struct with primitive fields
use fory_core::{Serializer, ForyDefault};
use fory_core::resolver::context::WriteContext;
use fory_core::error::Error;
use std::any::Any;

struct Point {
    x: f64,
    y: f64,
}

impl ForyDefault for Point {
    fn fory_default() -> Self {
        Point { x: 0.0, y: 0.0 }
    }
}

impl Serializer for Point {
    fn fory_write_data(&self, context: &mut WriteContext) -> Result<(), Error> {
        // Write each field in order
        context.writer.write_f64(self.x);
        context.writer.write_f64(self.y);
        Ok(())
    }

    fn fory_read_data(context: &mut fory_core::resolver::context::ReadContext) -> Result<Self, Error>
    where
        Self: Sized + fory_core::ForyDefault,
    {
        let x = context.reader.read_f64()?;
        let y = context.reader.read_f64()?;
        Ok(Point { x, y })
    }

    fn fory_type_id_dyn(&self, type_resolver: &fory_core::TypeResolver) -> Result<fory_core::TypeId, Error> {
        Self::fory_get_type_id(type_resolver)
    }

    fn as_any(&self) -> &dyn Any {
        self
    }
}
§Struct with nested serializable types
use fory_core::{Serializer, ForyDefault, RefMode};
use fory_core::resolver::context::WriteContext;
use fory_core::error::Error;
use std::any::Any;

struct Person {
    name: String,
    age: u32,
    scores: Vec<i32>,
}

impl ForyDefault for Person {
    fn fory_default() -> Self {
        Person {
            name: String::new(),
            age: 0,
            scores: Vec::new(),
        }
    }
}

impl Serializer for Person {
    fn fory_write_data(&self, context: &mut WriteContext) -> Result<(), Error> {
        // Write nested types using their Serializer implementations
        self.name.fory_write(context, RefMode::None, false, false)?;
        context.writer.write_u32(self.age);
        self.scores.fory_write(context, RefMode::None, false, true)?; // has_generics=true for Vec
        Ok(())
    }

    fn fory_read_data(context: &mut fory_core::resolver::context::ReadContext) -> Result<Self, Error>
    where
        Self: Sized + fory_core::ForyDefault,
    {
        let name = String::fory_read(context, RefMode::None, false)?;
        let age = context.reader.read_u32()?;
        let scores = Vec::<i32>::fory_read(context, RefMode::None, false)?;
        Ok(Person { name, age, scores })
    }

    fn fory_type_id_dyn(&self, type_resolver: &fory_core::TypeResolver) -> Result<fory_core::TypeId, Error> {
        Self::fory_get_type_id(type_resolver)
    }

    fn as_any(&self) -> &dyn Any {
        self
    }
}
§Implementation Guidelines
  1. Field order matters: Write fields in a consistent order; read them in the same order
  2. No metadata here: Don’t write type info or ref flags; that’s handled by fory_write
  3. Use Serializer for nested types: Leverage existing implementations for standard types
  4. Error handling: Propagate errors with ?; don’t swallow them
  5. Performance: Minimize allocations; write directly to the buffer
§Common Patterns
// Writing primitives directly
context.writer.write_i32(self.count);

// Writing nested Serializer types
self.nested.fory_write(context, false, false, false)?;

// Writing collections with generics
self.items.fory_write(context, false, false, true)?;

// Writing optional types
self.optional.fory_write(context, true, false, false)?; // write_ref_info=true
§See Also
Source

fn fory_read_data(context: &mut ReadContext<'_>) -> Result<Self, Error>
where Self: Sized + ForyDefault,

[USER IMPLEMENTATION REQUIRED] Deserialize the type’s data from the buffer.

This is the core deserialization method that you must implement for custom types. It should read all the type’s fields and data from the buffer in the same order they were written by fory_write_data.

§Parameters
  • context - Read context providing:
    • context.reader: Buffer to read binary data
    • context.type_resolver: Registry of type information
    • context.ref_resolver: Resolver for shared/circular references (if enabled)
§Type Requirements

Requires Self: Sized + ForyDefault:

  • Sized: Need to construct concrete instances on the stack
  • ForyDefault: Need to create default/null values for optional fields
§Reading Data

Use methods on context.reader to read primitive types:

  • read_i8(), read_i16(), read_i32(), read_i64(): Signed integers
  • read_u8(), read_u16(), read_u32(), read_u64(): Unsigned integers
  • read_f32(), read_f64(): Floating point numbers
  • read_bool(): Boolean values
  • read_bytes(): Raw byte arrays

For nested types that implement Serializer, call their deserialization:

// For types that implement Serializer
let field = T::fory_read(context, false, false)?;
§Examples
§Simple struct with primitive fields
use fory_core::{Serializer, ForyDefault};
use fory_core::resolver::context::{ReadContext, WriteContext};
use fory_core::error::Error;
use std::any::Any;

#[derive(Debug, PartialEq)]
struct Point {
    x: f64,
    y: f64,
}

impl ForyDefault for Point {
    fn fory_default() -> Self {
        Point { x: 0.0, y: 0.0 }
    }
}

impl Serializer for Point {
    fn fory_write_data(&self, context: &mut WriteContext) -> Result<(), Error> {
        context.writer.write_f64(self.x);
        context.writer.write_f64(self.y);
        Ok(())
    }

    fn fory_read_data(context: &mut ReadContext) -> Result<Self, Error>
    where
        Self: Sized + ForyDefault,
    {
        // Read fields in the same order as written
        let x = context.reader.read_f64()?;
        let y = context.reader.read_f64()?;
        Ok(Point { x, y })
    }

    fn fory_type_id_dyn(&self, type_resolver: &fory_core::TypeResolver) -> Result<fory_core::TypeId, Error> {
        Self::fory_get_type_id(type_resolver)
    }

    fn as_any(&self) -> &dyn Any {
        self
    }
}
§Struct with nested serializable types
use fory_core::{Serializer, ForyDefault, RefMode};
use fory_core::resolver::context::{ReadContext, WriteContext};
use fory_core::error::Error;
use std::any::Any;

#[derive(Debug, PartialEq)]
struct Person {
    name: String,
    age: u32,
    scores: Vec<i32>,
}

impl ForyDefault for Person {
    fn fory_default() -> Self {
        Person {
            name: String::new(),
            age: 0,
            scores: Vec::new(),
        }
    }
}

impl Serializer for Person {
    fn fory_write_data(&self, context: &mut WriteContext) -> Result<(), Error> {
        self.name.fory_write(context, RefMode::None, false, false)?;
        context.writer.write_u32(self.age);
        self.scores.fory_write(context, RefMode::None, false, true)?;
        Ok(())
    }

    fn fory_read_data(context: &mut ReadContext) -> Result<Self, Error>
    where
        Self: Sized + ForyDefault,
    {
        // Read nested types in the same order as written
        let name = String::fory_read(context, RefMode::None, false)?;
        let age = context.reader.read_u32()?;
        let scores = Vec::<i32>::fory_read(context, RefMode::None, false)?;
        Ok(Person { name, age, scores })
    }

    fn fory_type_id_dyn(&self, type_resolver: &fory_core::TypeResolver) -> Result<fory_core::TypeId, Error> {
        Self::fory_get_type_id(type_resolver)
    }

    fn as_any(&self) -> &dyn Any {
        self
    }
}
§Struct with optional fields
use fory_core::{Serializer, ForyDefault};
use fory_core::resolver::context::{ReadContext, WriteContext};
use fory_core::error::Error;
use std::any::Any;

#[derive(Debug, PartialEq)]
struct Config {
    name: String,
    timeout: Option<u32>,
}

impl ForyDefault for Config {
    fn fory_default() -> Self {
        Config {
            name: String::new(),
            timeout: None,
        }
    }
}

impl Serializer for Config {
    fn fory_write_data(&self, context: &mut WriteContext) -> Result<(), Error> {
        self.name.fory_write(context, false, false, false)?;
        // Option needs ref tracking to handle None
        self.timeout.fory_write(context, true, false, false)?;
        Ok(())
    }

    fn fory_read_data(context: &mut ReadContext) -> Result<Self, Error>
    where
        Self: Sized + ForyDefault,
    {
        let name = String::fory_read(context, false, false)?;
        // Read Option with ref tracking enabled
        let timeout = Option::<u32>::fory_read(context, true, false)?;
        Ok(Config { name, timeout })
    }

    fn fory_type_id_dyn(&self, type_resolver: &fory_core::TypeResolver) -> Result<fory_core::TypeId, Error> {
        Self::fory_get_type_id(type_resolver)
    }

    fn as_any(&self) -> &dyn Any {
        self
    }
}
§Implementation Guidelines
  1. Mirror write order: Read fields in the exact same order as fory_write_data writes them
  2. Error propagation: Use ? operator to propagate read errors
  3. No metadata reading: Don’t read ref flags or type info; that’s handled by fory_read
  4. Use Serializer for nested types: Leverage existing implementations
  5. Handle errors gracefully: Return descriptive errors for invalid data
§Common Patterns
// Reading primitives
let count = context.reader.read_i32()?;

// Reading nested Serializer types
let nested = T::fory_read(context, false, false)?;

// Reading collections
let items = Vec::<T>::fory_read(context, false, false)?;

// Reading optional types
let optional = Option::<T>::fory_read(context, true, false)?;
§Error Handling

Return errors for:

  • Buffer underflow: Not enough data to read
  • Invalid data: Data doesn’t match expected format
  • Version mismatch: Incompatible serialization format
if value > MAX_ALLOWED {
    return Err(Error::invalid_data(format!("Value {} exceeds maximum", value)));
}
§See Also
Source

fn fory_type_id_dyn( &self, type_resolver: &TypeResolver, ) -> Result<TypeId, Error>

[USER IMPLEMENTATION REQUIRED] Get the runtime type ID for this instance.

This method returns the type ID for the actual runtime type of the instance, which may differ from the static type for polymorphic types.

§Parameters
  • type_resolver - The type registry to query
§Returns

The numeric type ID for this instance’s runtime type.

§Implementation Pattern

For most types, simply delegate to fory_get_type_id:

fn fory_type_id_dyn(&self, type_resolver: &TypeResolver) -> Result<fory_core::TypeId, Error> {
    Self::fory_get_type_id(type_resolver)
}

For polymorphic types, return the actual runtime type:

fn fory_type_id_dyn(&self, type_resolver: &TypeResolver) -> Result<fory_core::TypeId, Error> {
    // Get the actual type ID based on runtime type
    self.get_actual_type().fory_get_type_id(type_resolver)
}
Source

fn as_any(&self) -> &(dyn Any + 'static)

[USER IMPLEMENTATION REQUIRED] Downcast to &dyn Any for dynamic type checking.

This method enables runtime type checking and downcasting, required for Fory’s type system integration.

§Returns

A reference to this instance as &dyn Any.

§Implementation Pattern

Always implement this by returning self:

fn as_any(&self) -> &dyn Any {
    self
}
§Implementation Notes
  • Required for all types implementing Serializer
  • Enables downcast_ref::<T>() on serialized values
  • Used by Fory’s polymorphic deserialization

Provided Methods§

Source

fn fory_write( &self, context: &mut WriteContext<'_>, ref_mode: RefMode, write_type_info: bool, has_generics: bool, ) -> Result<(), Error>
where Self: Sized,

Entry point for serialization.

This method orchestrates the complete serialization process, handling reference tracking, type information, and delegating to fory_write_data for the actual data serialization.

§Parameters
  • ref_mode - Controls how reference flags are written:
    • RefMode::None: Skip writing ref flag entirely
    • RefMode::NullOnly: Write NotNullValue flag (null check only)
    • RefMode::Tracking: Write ref tracking flags (for Rc/Arc/Weak)
  • write_type_info - When true, WRITES type information. When false, SKIPS writing type info.
  • has_generics - Indicates if the type has generic parameters (used for collection meta).
§Default Implementation (Fast Path)

The default implementation uses a fast path suitable for primitives, strings, and time types:

  1. If ref_mode != RefMode::None, writes RefFlag::NotNullValue
  2. If write_type_info is true, calls fory_write_type_info
  3. Calls fory_write_data_generic to write the actual data
§When to Override

You should override this method for:

  • Option types: Need to handle None with RefFlag::Null
  • Reference types (Rc/Arc/Weak): Need full ref tracking with RefWriter
  • Polymorphic types: Need to write actual runtime type instead of static type

For regular types (structs, primitives, collections), the default implementation is sufficient.

Source

fn fory_write_data_generic( &self, context: &mut WriteContext<'_>, has_generics: bool, ) -> Result<(), Error>

Write data with generic type parameter support.

This method is primarily used by collection types (Vec, HashMap, etc.) that need to write generic type information for their elements. For most types, this simply delegates to fory_write_data.

§Parameters
  • context - Write context containing the buffer and type resolver
  • has_generics - Indicates if the type has generic parameters that need metadata
§Default Implementation

The default implementation ignores has_generics and forwards to fory_write_data:

fn fory_write_data_generic(&self, context: &mut WriteContext, has_generics: bool) -> Result<(), Error> {
    self.fory_write_data(context)
}
§When to Override

Override this method for:

  • Collection types (Vec, HashMap, HashSet, etc.): Need to write element/key/value type metadata
  • Generic containers: Any type that contains type parameters requiring runtime metadata

For non-generic types (primitives, simple structs), use the default implementation.

§Implementation Notes
  • Implemented by Fory for all collection types
  • User types with custom serialization for non-generic types don’t need to override
  • Focus on implementing fory_write_data for custom types
Source

fn fory_write_type_info(context: &mut WriteContext<'_>) -> Result<(), Error>
where Self: Sized,

Write type metadata to the buffer.

This method writes type information that allows Fory to identify and deserialize the type correctly, especially for polymorphic scenarios.

§Default Implementation

The default implementation writes:

  1. Static type ID from fory_static_type_id
  2. Rust’s std::any::TypeId for runtime type identification
fn fory_write_type_info(context: &mut WriteContext) -> Result<(), Error> {
    let rs_type_id = std::any::TypeId::of::<Self>();
    context.write_any_type_info(Self::fory_static_type_id() as u32, rs_type_id)?;
    Ok(())
}
§When to Override

Override this method for:

  • Built-in types: Fory’s internal types override for optimized performance
  • Custom type ID schemes: If you need special type identification logic

For user types with custom serialization, the default implementation is typically sufficient.

§Implementation Notes
  • Called by fory_write when write_type_info is true
  • Implemented by Fory for all built-in types with optimized paths
  • User types with custom serialization rarely need to override this
Source

fn fory_read( context: &mut ReadContext<'_>, ref_mode: RefMode, read_type_info: bool, ) -> Result<Self, Error>
where Self: Sized + ForyDefault,

Entry point for deserialization.

This method orchestrates the complete deserialization process, handling reference tracking, type information validation, and delegating to fory_read_data for the actual data deserialization.

§Parameters
  • ref_mode - Controls how reference flags are read:
    • RefMode::None: Skip reading ref flag entirely
    • RefMode::NullOnly: Read flag, return default on null
    • RefMode::Tracking: Full ref tracking (for Rc/Arc/Weak)
  • read_type_info - When true, READS type information from buffer. When false, SKIPS reading type info.
§Type Requirements

This method requires Self: Sized + ForyDefault because:

  • Sized: Need to construct concrete instances
  • ForyDefault: Need to create default/null values for optional types
§Default Implementation (Fast Path)

The default implementation uses a fast path suitable for primitives, strings, and time types:

  1. If ref_mode != RefMode::None:
    • Reads ref flag from buffer
    • Returns ForyDefault::fory_default() for null values
  2. If read_type_info is true, calls fory_read_type_info
  3. Calls fory_read_data to read the actual data
§When to Override

Override this method for:

  • Option types: Need custom null handling logic
  • Reference types (Rc/Arc/Weak): Need custom ref tracking with RefReader
  • Polymorphic types: Need to dispatch based on actual runtime type

For regular types (structs, primitives, collections), the default implementation is sufficient.

Source

fn fory_read_with_type_info( context: &mut ReadContext<'_>, ref_mode: RefMode, type_info: Rc<TypeInfo>, ) -> Result<Self, Error>
where Self: Sized + ForyDefault,

Deserialize with pre-read type information.

This method is used when type information has already been read from the buffer and needs to be passed to the deserialization logic. This is common in polymorphic deserialization scenarios where the runtime type differs from the static type.

§Parameters
  • ref_mode - Controls how reference flags are read (see fory_read)
  • type_info - Type information that has already been read ahead. DO NOT read type info again from buffer.
§Important

DO NOT read type info from the buffer in this method. The type_info parameter contains the already-read type metadata. Reading it again will cause buffer position errors.

§Default Implementation

The default implementation ignores the provided type_info and delegates to fory_read:

fn fory_read_with_type_info(
    context: &mut ReadContext,
    ref_mode: RefMode,
    type_info: Rc<TypeInfo>,
) -> Result<Self, Error> {
    // Ignore type_info since static type matches
    Self::fory_read(context, ref_mode, false) // read_type_info=false
}

This works for:

  • Monomorphic types: Static type matches runtime type
  • Final types: Types that don’t participate in polymorphism
  • User-defined types: Types registered with Fory that don’t require polymorphism
§When to Override

Override this method for:

  • Trait objects (dyn Trait): Need to dispatch to concrete implementation based on type_info
  • Reference types with polymorphic targets: Rc<dyn Trait>, Arc<dyn Trait>
  • Custom polymorphic types: Types with runtime type variation
Source

fn fory_read_type_info(context: &mut ReadContext<'_>) -> Result<(), Error>
where Self: Sized,

Read and validate type metadata from the buffer.

This method reads type information to verify that the data in the buffer matches the expected type. It’s the counterpart to fory_write_type_info.

§Default Implementation

The default implementation reads and validates the type info:

fn fory_read_type_info(context: &mut ReadContext) -> Result<(), Error> {
    context.read_any_type_info()?;
    Ok(())
}
§When to Override

Override this method for:

  • Built-in types: Fory’s internal types override for optimized performance
  • Custom validation logic: If you need special type checking

For user types with custom serialization, the default implementation is typically sufficient.

§Implementation Notes
  • Called by fory_read when read_type_info is true
  • Implemented by Fory for all built-in types with optimized paths
  • User types with custom serialization rarely need to override this
Source

fn fory_is_option() -> bool
where Self: Sized,

Check if this type is Option<T>.

§Returns
  • true if the type is Option<T>
  • false for all other types (default)
§Implementation Notes
  • Implemented by Fory for Option<T> to return true
  • User types with custom serialization should not override this
  • Used internally for null handling optimization
Source

fn fory_is_none(&self) -> bool

Check if this instance represents a None value.

This method is used for runtime checking of optional values.

§Returns
  • true if the instance is Option::None
  • false for all other values (default)
§Implementation Notes
  • Implemented by Fory for Option<T> to check None state
  • User types with custom serialization should not override this
  • Used with fory_is_option for null handling
Source

fn fory_is_polymorphic() -> bool
where Self: Sized,

Check if this type supports polymorphic serialization.

Polymorphic types can have different runtime types than their static type, requiring special handling during serialization and deserialization.

§Returns
  • true if the type is polymorphic (trait objects, dynamic dispatch)
  • false for monomorphic types (default)
§Examples of Polymorphic Types
  • Trait objects: Box<dyn Trait>, Rc<dyn Trait>, Arc<dyn Trait>
§Implementation Notes
  • Implemented by Fory for all polymorphic types
  • User types with custom serialization typically should not override this
  • Used to determine if type info must be written
Source

fn fory_is_shared_ref() -> bool
where Self: Sized,

Check if this type is a shared reference (Rc/Arc).

Shared references require special handling for reference tracking to support proper sharing and circular reference detection.

§Returns
  • true if the type is Rc<T> or Arc<T>
  • false for all other types (default)
§Implementation Notes
  • Implemented by Fory for Rc<T> and Arc<T>
  • User types with custom serialization should not override this
  • Used for reference tracking and deduplication
Source

fn fory_is_wrapper_type() -> bool
where Self: Sized,

Source

fn fory_static_type_id() -> TypeId
where Self: Sized,

Get the static Fory type ID for this type.

Type IDs are Fory’s internal type identification system, separate from Rust’s std::any::TypeId. They’re used for cross-language serialization and protocol compatibility.

§Returns
  • For built-in types: Specific type ID (e.g., TypeId::I32, TypeId::STRING)
  • For external types: TypeId::EXT (default)
§Type ID Categories
  • Primitives: BOOL, I8, I16, I32, I64, U8, U16, U32, U64, USIZE, U128, F32, F64
  • Strings: STRING
  • Collections: LIST, MAP, SET
  • Structs: STRUCT
  • Enums: ENUM
  • User types: EXT for user types with custom serialization logic
§Implementation Notes
  • Default returns TypeId::EXT for user types
  • Fory implements specific type IDs for all built-in types
  • User types with custom serialization should use the default
  • This is a compile-time constant
Source

fn fory_get_type_id(type_resolver: &TypeResolver) -> Result<TypeId, Error>
where Self: Sized,

Get the registered type ID from the type resolver.

This method looks up the type’s assigned ID in the type registry, which is required for serialization of external types.

§Parameters
  • type_resolver - The type registry to query
§Returns

The numeric type ID assigned to this type during registration.

§Errors

Returns an error if the type is not registered with the resolver.

§Implementation Notes
  • Default implementation looks up via std::any::TypeId
  • User types must be registered before serialization
  • Built-in types have pre-assigned IDs
  • This is typically called by fory_type_id_dyn
Source

fn fory_get_type_info( type_resolver: &TypeResolver, ) -> Result<Rc<TypeInfo>, Error>
where Self: Sized,

Source

fn fory_concrete_type_id(&self) -> TypeId

Get Rust’s std::any::TypeId for this instance.

Returns the runtime type identifier from Rust’s type system. This is used for type resolution and registration.

§Returns

The std::any::TypeId for this instance’s concrete type.

§Implementation Notes
  • Default implementation uses TypeId::of::<Self>()
  • User types with custom serialization should not override this
  • Used by type resolution infrastructure
Source

fn fory_reserved_space() -> usize
where Self: Sized,

Hint for buffer pre-allocation size.

This method provides a size hint for how much buffer space to pre-allocate before serializing this type. Accurate hints improve performance by reducing buffer reallocations.

§Returns
  • Estimated maximum size in bytes for this type
  • 0 if unknown or variable size (default)
§Implementation Guidelines

Return a conservative upper bound:

fn fory_reserved_space() -> usize {
    std::mem::size_of::<Self>() + overhead
}
§Examples
  • Fixed-size struct: std::mem::size_of::<Self>() + metadata_size
  • Variable-size: Return 0 (collections, strings)
§Implementation Notes
  • Default returns 0 (no pre-allocation)
  • Fory implements size hints for fixed-size types
  • User types with custom serialization can override for performance
  • Overestimation wastes memory; underestimation requires reallocation

Trait Implementations§

Source§

impl ForyDefault for Box<dyn Serializer>

Source§

fn fory_default() -> Box<dyn Serializer>

Creates a default value for this type. Read more
Source§

impl Serializer for Box<dyn Serializer>

Source§

fn fory_concrete_type_id(&self) -> TypeId

Get Rust’s std::any::TypeId for this instance. Read more
Source§

fn fory_write( &self, context: &mut WriteContext<'_>, ref_mode: RefMode, write_type_info: bool, has_generics: bool, ) -> Result<(), Error>

Entry point for serialization. Read more
Source§

fn fory_write_data(&self, context: &mut WriteContext<'_>) -> Result<(), Error>

[USER IMPLEMENTATION REQUIRED] Serialize the type’s data to the buffer. Read more
Source§

fn fory_write_data_generic( &self, context: &mut WriteContext<'_>, has_generics: bool, ) -> Result<(), Error>

Write data with generic type parameter support. Read more
Source§

fn fory_type_id_dyn( &self, type_resolver: &TypeResolver, ) -> Result<TypeId, Error>

[USER IMPLEMENTATION REQUIRED] Get the runtime type ID for this instance. Read more
Source§

fn as_any(&self) -> &(dyn Any + 'static)

[USER IMPLEMENTATION REQUIRED] Downcast to &dyn Any for dynamic type checking. Read more
Source§

fn fory_is_polymorphic() -> bool

Check if this type supports polymorphic serialization. Read more
Source§

fn fory_write_type_info(_context: &mut WriteContext<'_>) -> Result<(), Error>

Write type metadata to the buffer. Read more
Source§

fn fory_read_type_info(context: &mut ReadContext<'_>) -> Result<(), Error>

Read and validate type metadata from the buffer. Read more
Source§

fn fory_read( context: &mut ReadContext<'_>, ref_mode: RefMode, read_type_info: bool, ) -> Result<Box<dyn Serializer>, Error>

Entry point for deserialization. Read more
Source§

fn fory_read_with_type_info( context: &mut ReadContext<'_>, ref_mode: RefMode, type_info: Rc<TypeInfo>, ) -> Result<Box<dyn Serializer>, Error>

Deserialize with pre-read type information. Read more
Source§

fn fory_read_data( _context: &mut ReadContext<'_>, ) -> Result<Box<dyn Serializer>, Error>

[USER IMPLEMENTATION REQUIRED] Deserialize the type’s data from the buffer. Read more
Source§

fn fory_is_option() -> bool
where Self: Sized,

Check if this type is Option<T>. Read more
Source§

fn fory_is_none(&self) -> bool

Check if this instance represents a None value. Read more
Source§

fn fory_is_shared_ref() -> bool
where Self: Sized,

Check if this type is a shared reference (Rc/Arc). Read more
Source§

fn fory_is_wrapper_type() -> bool
where Self: Sized,

Source§

fn fory_static_type_id() -> TypeId
where Self: Sized,

Get the static Fory type ID for this type. Read more
Source§

fn fory_get_type_id(type_resolver: &TypeResolver) -> Result<TypeId, Error>
where Self: Sized,

Get the registered type ID from the type resolver. Read more
Source§

fn fory_get_type_info( type_resolver: &TypeResolver, ) -> Result<Rc<TypeInfo>, Error>
where Self: Sized,

Source§

fn fory_reserved_space() -> usize
where Self: Sized,

Hint for buffer pre-allocation size. Read more

Implementations on Foreign Types§

Source§

impl Serializer for bool

Source§

impl Serializer for f32

Source§

impl Serializer for f64

Source§

impl Serializer for i8

Source§

impl Serializer for i16

Source§

impl Serializer for i32

Source§

impl Serializer for i64

Source§

impl Serializer for i128

Source§

impl Serializer for isize

Source§

impl Serializer for u8

Source§

impl Serializer for u16

Source§

impl Serializer for u32

Source§

impl Serializer for u64

Source§

impl Serializer for u128

Source§

impl Serializer for ()

Source§

impl Serializer for usize

Source§

impl Serializer for Box<dyn Any>

Source§

fn fory_write( &self, context: &mut WriteContext<'_>, ref_mode: RefMode, write_type_info: bool, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_write_data_generic( &self, context: &mut WriteContext<'_>, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_write_data(&self, context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_read( context: &mut ReadContext<'_>, ref_mode: RefMode, read_type_info: bool, ) -> Result<Box<dyn Any>, Error>

Source§

fn fory_read_with_type_info( context: &mut ReadContext<'_>, ref_mode: RefMode, type_info: Rc<TypeInfo>, ) -> Result<Box<dyn Any>, Error>
where Box<dyn Any>: Sized + ForyDefault,

Source§

fn fory_read_data(_: &mut ReadContext<'_>) -> Result<Box<dyn Any>, Error>

Source§

fn fory_get_type_id(_: &TypeResolver) -> Result<TypeId, Error>

Source§

fn fory_type_id_dyn( &self, type_resolver: &TypeResolver, ) -> Result<TypeId, Error>

Source§

fn fory_concrete_type_id(&self) -> TypeId

Source§

fn fory_is_polymorphic() -> bool

Source§

fn fory_is_shared_ref() -> bool

Source§

fn fory_static_type_id() -> TypeId

Source§

fn fory_write_type_info(_context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_read_type_info(_context: &mut ReadContext<'_>) -> Result<(), Error>

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl Serializer for Box<dyn Serializer>

Source§

fn fory_concrete_type_id(&self) -> TypeId

Source§

fn fory_write( &self, context: &mut WriteContext<'_>, ref_mode: RefMode, write_type_info: bool, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_write_data(&self, context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_write_data_generic( &self, context: &mut WriteContext<'_>, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_type_id_dyn( &self, type_resolver: &TypeResolver, ) -> Result<TypeId, Error>

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn fory_is_polymorphic() -> bool

Source§

fn fory_write_type_info(_context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_read_type_info(context: &mut ReadContext<'_>) -> Result<(), Error>

Source§

fn fory_read( context: &mut ReadContext<'_>, ref_mode: RefMode, read_type_info: bool, ) -> Result<Box<dyn Serializer>, Error>

Source§

fn fory_read_with_type_info( context: &mut ReadContext<'_>, ref_mode: RefMode, type_info: Rc<TypeInfo>, ) -> Result<Box<dyn Serializer>, Error>

Source§

fn fory_read_data( _context: &mut ReadContext<'_>, ) -> Result<Box<dyn Serializer>, Error>

Source§

impl Serializer for Rc<dyn Any>

Source§

fn fory_write( &self, context: &mut WriteContext<'_>, ref_mode: RefMode, write_type_info: bool, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_write_data(&self, context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_write_data_generic( &self, context: &mut WriteContext<'_>, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_read( context: &mut ReadContext<'_>, ref_mode: RefMode, read_type_info: bool, ) -> Result<Rc<dyn Any>, Error>

Source§

fn fory_read_with_type_info( context: &mut ReadContext<'_>, ref_mode: RefMode, type_info: Rc<TypeInfo>, ) -> Result<Rc<dyn Any>, Error>
where Rc<dyn Any>: Sized + ForyDefault,

Source§

fn fory_read_data(_: &mut ReadContext<'_>) -> Result<Rc<dyn Any>, Error>

Source§

fn fory_get_type_id(_: &TypeResolver) -> Result<TypeId, Error>

Source§

fn fory_type_id_dyn( &self, type_resolver: &TypeResolver, ) -> Result<TypeId, Error>

Source§

fn fory_concrete_type_id(&self) -> TypeId

Source§

fn fory_is_shared_ref() -> bool

Source§

fn fory_is_polymorphic() -> bool

Source§

fn fory_static_type_id() -> TypeId

Source§

fn fory_write_type_info(_context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_read_type_info(_context: &mut ReadContext<'_>) -> Result<(), Error>

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl Serializer for String

Source§

impl Serializer for Arc<dyn Any>

Source§

fn fory_write( &self, context: &mut WriteContext<'_>, ref_mode: RefMode, write_type_info: bool, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_write_data(&self, context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_write_data_generic( &self, context: &mut WriteContext<'_>, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_read( context: &mut ReadContext<'_>, ref_mode: RefMode, read_type_info: bool, ) -> Result<Arc<dyn Any>, Error>

Source§

fn fory_read_with_type_info( context: &mut ReadContext<'_>, ref_mode: RefMode, type_info: Rc<TypeInfo>, ) -> Result<Arc<dyn Any>, Error>
where Arc<dyn Any>: Sized + ForyDefault,

Source§

fn fory_read_data(_: &mut ReadContext<'_>) -> Result<Arc<dyn Any>, Error>

Source§

fn fory_get_type_id(_type_resolver: &TypeResolver) -> Result<TypeId, Error>

Source§

fn fory_type_id_dyn( &self, type_resolver: &TypeResolver, ) -> Result<TypeId, Error>

Source§

fn fory_concrete_type_id(&self) -> TypeId

Source§

fn fory_is_polymorphic() -> bool

Source§

fn fory_is_shared_ref() -> bool

Source§

fn fory_static_type_id() -> TypeId

Source§

fn fory_write_type_info(_context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_read_type_info(_context: &mut ReadContext<'_>) -> Result<(), Error>

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl Serializer for Duration

Source§

impl Serializer for NaiveDate

Source§

impl Serializer for NaiveDateTime

Source§

impl<K, V> Serializer for BTreeMap<K, V>

Source§

impl<K, V> Serializer for HashMap<K, V>

Source§

impl<T0> Serializer for (T0,)
where T0: Serializer + ForyDefault,

Source§

impl<T0, T1> Serializer for (T0, T1)

Source§

impl<T0, T1, T2> Serializer for (T0, T1, T2)

Source§

impl<T0, T1, T2, T3> Serializer for (T0, T1, T2, T3)

Source§

impl<T0, T1, T2, T3, T4> Serializer for (T0, T1, T2, T3, T4)

Source§

impl<T0, T1, T2, T3, T4, T5> Serializer for (T0, T1, T2, T3, T4, T5)

Source§

impl<T0, T1, T2, T3, T4, T5, T6> Serializer for (T0, T1, T2, T3, T4, T5, T6)

Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7> Serializer for (T0, T1, T2, T3, T4, T5, T6, T7)

Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8> Serializer for (T0, T1, T2, T3, T4, T5, T6, T7, T8)

Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> Serializer for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)

Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> Serializer for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)

Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Serializer for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Serializer for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)

Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> Serializer for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)

Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> Serializer for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)

Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> Serializer for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)

Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> Serializer for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16)

Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17> Serializer for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17)

Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18> Serializer for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18)

Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19> Serializer for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19)

Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20> Serializer for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20)

Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21> Serializer for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21)

Source§

impl<T> Serializer for Option<T>

Source§

fn fory_write( &self, context: &mut WriteContext<'_>, ref_mode: RefMode, write_type_info: bool, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_write_data(&self, context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_write_type_info(context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_read( context: &mut ReadContext<'_>, ref_mode: RefMode, read_type_info: bool, ) -> Result<Option<T>, Error>
where Option<T>: Sized + ForyDefault,

Source§

fn fory_read_with_type_info( context: &mut ReadContext<'_>, ref_mode: RefMode, type_info: Rc<TypeInfo>, ) -> Result<Option<T>, Error>
where Option<T>: Sized + ForyDefault,

Source§

fn fory_read_data(context: &mut ReadContext<'_>) -> Result<Option<T>, Error>

Source§

fn fory_read_type_info(context: &mut ReadContext<'_>) -> Result<(), Error>

Source§

fn fory_reserved_space() -> usize

Source§

fn fory_get_type_id(type_resolver: &TypeResolver) -> Result<TypeId, Error>

Source§

fn fory_type_id_dyn( &self, type_resolver: &TypeResolver, ) -> Result<TypeId, Error>

Source§

fn fory_is_option() -> bool

Source§

fn fory_is_none(&self) -> bool

Source§

fn fory_static_type_id() -> TypeId

Source§

fn fory_is_wrapper_type() -> bool
where Option<T>: Sized,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T> Serializer for Box<T>

Source§

impl<T> Serializer for BinaryHeap<T>
where T: Serializer + ForyDefault + Ord,

Source§

impl<T> Serializer for BTreeSet<T>
where T: Serializer + ForyDefault + Ord,

Source§

impl<T> Serializer for LinkedList<T>

Source§

impl<T> Serializer for VecDeque<T>

Source§

impl<T> Serializer for Rc<T>
where T: Serializer + ForyDefault + 'static,

Source§

fn fory_is_shared_ref() -> bool

Source§

fn fory_write( &self, context: &mut WriteContext<'_>, ref_mode: RefMode, write_type_info: bool, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_write_data_generic( &self, context: &mut WriteContext<'_>, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_write_data(&self, context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_write_type_info(context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_read( context: &mut ReadContext<'_>, ref_mode: RefMode, read_type_info: bool, ) -> Result<Rc<T>, Error>

Source§

fn fory_read_with_type_info( context: &mut ReadContext<'_>, ref_mode: RefMode, typeinfo: Rc<TypeInfo>, ) -> Result<Rc<T>, Error>
where Rc<T>: Sized + ForyDefault,

Source§

fn fory_read_data(context: &mut ReadContext<'_>) -> Result<Rc<T>, Error>

Source§

fn fory_read_type_info(context: &mut ReadContext<'_>) -> Result<(), Error>

Source§

fn fory_reserved_space() -> usize

Source§

fn fory_get_type_id(type_resolver: &TypeResolver) -> Result<TypeId, Error>

Source§

fn fory_get_type_info( type_resolver: &TypeResolver, ) -> Result<Rc<TypeInfo>, Error>

Source§

fn fory_type_id_dyn( &self, type_resolver: &TypeResolver, ) -> Result<TypeId, Error>

Source§

fn fory_static_type_id() -> TypeId

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T> Serializer for Arc<T>
where T: Serializer + ForyDefault + Send + Sync + 'static,

Source§

fn fory_is_shared_ref() -> bool

Source§

fn fory_write( &self, context: &mut WriteContext<'_>, ref_mode: RefMode, write_type_info: bool, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_write_data_generic( &self, context: &mut WriteContext<'_>, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_write_data(&self, context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_write_type_info(context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_read( context: &mut ReadContext<'_>, ref_mode: RefMode, read_type_info: bool, ) -> Result<Arc<T>, Error>

Source§

fn fory_read_with_type_info( context: &mut ReadContext<'_>, ref_mode: RefMode, typeinfo: Rc<TypeInfo>, ) -> Result<Arc<T>, Error>
where Arc<T>: Sized + ForyDefault,

Source§

fn fory_read_data(context: &mut ReadContext<'_>) -> Result<Arc<T>, Error>

Source§

fn fory_read_type_info(context: &mut ReadContext<'_>) -> Result<(), Error>

Source§

fn fory_reserved_space() -> usize

Source§

fn fory_get_type_id(type_resolver: &TypeResolver) -> Result<TypeId, Error>

Source§

fn fory_get_type_info( type_resolver: &TypeResolver, ) -> Result<Rc<TypeInfo>, Error>

Source§

fn fory_type_id_dyn( &self, type_resolver: &TypeResolver, ) -> Result<TypeId, Error>

Source§

fn fory_static_type_id() -> TypeId

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T> Serializer for Vec<T>

Source§

impl<T> Serializer for RefCell<T>

Serializer impl for RefCell<T>

Simply delegates to the serializer for T, allowing interior mutable containers to be included in serialized graphs.

Source§

fn fory_read( context: &mut ReadContext<'_>, ref_mode: RefMode, read_type_info: bool, ) -> Result<RefCell<T>, Error>

Source§

fn fory_read_with_type_info( context: &mut ReadContext<'_>, ref_mode: RefMode, type_info: Rc<TypeInfo>, ) -> Result<RefCell<T>, Error>

Source§

fn fory_read_data(context: &mut ReadContext<'_>) -> Result<RefCell<T>, Error>

Source§

fn fory_read_type_info(context: &mut ReadContext<'_>) -> Result<(), Error>

Source§

fn fory_write( &self, context: &mut WriteContext<'_>, ref_mode: RefMode, write_type_info: bool, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_write_data_generic( &self, context: &mut WriteContext<'_>, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_write_data(&self, context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_write_type_info(context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_reserved_space() -> usize

Source§

fn fory_get_type_id(type_resolver: &TypeResolver) -> Result<TypeId, Error>

Source§

fn fory_get_type_info( type_resolver: &TypeResolver, ) -> Result<Rc<TypeInfo>, Error>

Source§

fn fory_type_id_dyn( &self, type_resolver: &TypeResolver, ) -> Result<TypeId, Error>

Source§

fn fory_static_type_id() -> TypeId
where RefCell<T>: Sized,

Source§

fn fory_is_wrapper_type() -> bool
where RefCell<T>: Sized,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T> Serializer for PhantomData<T>
where T: 'static,

Source§

impl<T> Serializer for HashSet<T>
where T: Serializer + ForyDefault + Eq + Hash,

Source§

impl<T> Serializer for Mutex<T>

Serializer impl for Mutex<T>

Simply delegates to the serializer for T, allowing thread-safe interior mutable containers to be included in serialized graphs.

Source§

fn fory_write( &self, context: &mut WriteContext<'_>, ref_mode: RefMode, write_type_info: bool, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_write_data_generic( &self, context: &mut WriteContext<'_>, has_generics: bool, ) -> Result<(), Error>

Source§

fn fory_write_data(&self, context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_write_type_info(context: &mut WriteContext<'_>) -> Result<(), Error>

Source§

fn fory_reserved_space() -> usize

Source§

fn fory_read( context: &mut ReadContext<'_>, ref_mode: RefMode, read_type_info: bool, ) -> Result<Mutex<T>, Error>
where Mutex<T>: Sized + ForyDefault,

Source§

fn fory_read_with_type_info( context: &mut ReadContext<'_>, ref_mode: RefMode, type_info: Rc<TypeInfo>, ) -> Result<Mutex<T>, Error>
where Mutex<T>: Sized + ForyDefault,

Source§

fn fory_read_data(context: &mut ReadContext<'_>) -> Result<Mutex<T>, Error>

Source§

fn fory_read_type_info(context: &mut ReadContext<'_>) -> Result<(), Error>

Source§

fn fory_get_type_id(type_resolver: &TypeResolver) -> Result<TypeId, Error>

Source§

fn fory_get_type_info( type_resolver: &TypeResolver, ) -> Result<Rc<TypeInfo>, Error>

Source§

fn fory_type_id_dyn( &self, type_resolver: &TypeResolver, ) -> Result<TypeId, Error>

Source§

fn fory_static_type_id() -> TypeId

Source§

fn fory_is_wrapper_type() -> bool
where Mutex<T>: Sized,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T, const N: usize> Serializer for [T; N]

Implementors§

Source§

impl<T> Serializer for ArcWeak<T>
where T: Serializer + ForyDefault + Send + Sync + 'static,

Source§

impl<T> Serializer for RcWeak<T>
where T: Serializer + ForyDefault + 'static,