ByteableRaw

Trait ByteableRaw 

Source
pub trait ByteableRaw: Byteable + From<Self::Raw> {
    type Raw: Byteable + From<Self>;
}
Expand description

A trait for types that have a corresponding raw representation type.

This trait is automatically implemented by the #[derive(Byteable)] macro to expose the generated raw struct type. The raw type is typically a #[repr(C, packed)] struct with endianness wrappers and is used internally for byte conversion.

This trait enables better type safety when using nested Byteable structs with the #[byteable(transparent)] attribute. Instead of storing nested structs as raw byte arrays ([u8; N]), the parent struct’s raw type can directly reference the child struct’s raw type, maintaining type information throughout the conversion process.

§Examples

use byteable::{Byteable, ByteableRaw};

#[derive(Clone, Copy, Byteable)]
struct Inner {
    value: u8,
}

#[derive(Clone, Copy, Byteable)]
struct Outer {
    #[byteable(transparent)]
    inner: Inner,  // Uses Inner::Raw instead of [u8; 1]
}

// Both Inner and Outer automatically implement ByteableRaw via derive(Byteable)
// The generated raw types are properly nested and type-safe

Required Associated Types§

Source

type Raw: Byteable + From<Self>

The raw type used for byte conversion.

This is typically a #[repr(C, packed)] struct with endianness wrappers that handles the actual memory layout and byte-level operations.

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§