Trait multiboot2::TagTrait

source ·
pub trait TagTrait: Pointee {
    // Required method
    fn dst_size(base_tag: &Tag) -> Self::Metadata;

    // Provided method
    unsafe fn from_base_tag<'a>(tag: &Tag) -> &'a Self { ... }
}
Expand description

A trait to abstract over all sized and unsized tags (DSTs). For sized tags, this trait does not much. For DSTs, a TagTrait::dst_size implementation must me provided, which returns the right size hint for the dynamically sized portion of the struct.

The TagTrait::from_base_tag method has a default implementation for all tags that are Sized.

Trivia

This crate uses the Pointee-abstraction of the ptr_meta crate to create fat pointers.

Required Methods§

source

fn dst_size(base_tag: &Tag) -> Self::Metadata

Returns the amount of items in the dynamically sized portion of the DST. Note that this is not the amount of bytes. So if the dynamically sized portion is 16 bytes in size and each element is 4 bytes big, then this function must return 4.

Provided Methods§

source

unsafe fn from_base_tag<'a>(tag: &Tag) -> &'a Self

Creates a reference to a (dynamically sized) tag type in a safe way. DST tags need to implement a proper Self::dst_size implementation.

Safety

Callers must be sure that the “size” field of the provided Tag is sane and the underlying memory valid. The implementation of this trait must have a correct Self::dst_size implementation.

Implementors§