Skip to main content

Factory

Trait Factory 

Source
pub trait Factory<Trait: ArchiveTrait + ?Sized>: Send + Sync {
    // Required methods
    fn size_of(&self) -> usize;
    fn default_box(&self) -> Box<Trait>;
    fn with(&self, f: &mut dyn FnMut(&mut Trait));
    unsafe fn archived_value<'a>(
        &self,
        bytes: &'a [u8],
        pos: usize,
    ) -> &'a Trait::Archived;

    // Provided method
    fn is_zst(&self) -> bool { ... }
}
Expand description

Create instances of a concrete type wrapped in a trait object.

Required Methods§

Source

fn size_of(&self) -> usize

Size of the underlying concrete type.

Source

fn default_box(&self) -> Box<Trait>

Create an instance of the underlying concrete type with the default value on the heap.

Source

fn with(&self, f: &mut dyn FnMut(&mut Trait))

Creates an instance of the underlying concrete type with the default value on the stack and passes it as an argument to the provided closure.

Source

unsafe fn archived_value<'a>( &self, bytes: &'a [u8], pos: usize, ) -> &'a Trait::Archived

Casts an archived value from the given byte slice at the given position.

§Safety

The specified offset must contain an archived instance of the concrete type that this factory manages.

Provided Methods§

Source

fn is_zst(&self) -> bool

True iff the underlying concrete type is a zero-sized type.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§