amebazii::types

Trait BinarySize

Source
pub trait BinarySize {
    // Required method
    fn binary_size() -> usize;
}
Expand description

A trait for types that can provide their binary size.

This trait allows types to specify the size, in bytes, of their serialized binary representation. Types that implement this trait must define the binary_size method to return the size of the type’s binary form.

§Example

use amebazii::types::BinarySize;
struct MyStruct {
    field1: u32,
    field2: String,
}

impl BinarySize for MyStruct {
    fn binary_size() -> usize {
        // Return the size of `MyStruct`'s binary representation
        std::mem::size_of::<u32>() + field2.len()
    }
}

Required Methods§

Source

fn binary_size() -> usize

Returns the binary size of the type in bytes.

§Returns
  • usize: The number of bytes required to serialize the type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§