wiggle

Trait GuestType

source
pub trait GuestType: Sized {
    // Required methods
    fn guest_size() -> u32;
    fn guest_align() -> usize;
    fn read(
        mem: &GuestMemory<'_>,
        ptr: GuestPtr<Self>,
    ) -> Result<Self, GuestError>;
    fn write(
        mem: &mut GuestMemory<'_>,
        ptr: GuestPtr<Self>,
        val: Self,
    ) -> Result<(), GuestError>;
}
Expand description

A trait for types that are intended to be pointees in GuestPtr<T>.

This trait abstracts how to read/write information from the guest memory, as well as how to offset elements in an array of guest memory. This layer of abstraction allows the guest representation of a type to be different from the host representation of a type, if necessary. It also allows for validation when reading/writing.

Required Methods§

source

fn guest_size() -> u32

Returns the size, in bytes, of this type in the guest memory.

source

fn guest_align() -> usize

Returns the required alignment of this type, in bytes, for both guest and host memory.

source

fn read(mem: &GuestMemory<'_>, ptr: GuestPtr<Self>) -> Result<Self, GuestError>

Reads this value from the provided ptr.

Must internally perform any safety checks necessary and is allowed to fail if the bytes pointed to are also invalid.

Typically if you’re implementing this by hand you’ll want to delegate to other safe implementations of this trait (e.g. for primitive types like u32) rather than writing lots of raw code yourself.

source

fn write( mem: &mut GuestMemory<'_>, ptr: GuestPtr<Self>, val: Self, ) -> Result<(), GuestError>

Writes a value to ptr after verifying that ptr is indeed valid to store val.

Similar to read, you’ll probably want to implement this in terms of other primitives.

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.

Implementations on Foreign Types§

source§

impl GuestType for f32

source§

fn guest_size() -> u32

source§

fn guest_align() -> usize

source§

fn read(mem: &GuestMemory<'_>, ptr: GuestPtr<Self>) -> Result<Self, GuestError>

source§

fn write( mem: &mut GuestMemory<'_>, ptr: GuestPtr<Self>, val: Self, ) -> Result<(), GuestError>

source§

impl GuestType for f64

source§

fn guest_size() -> u32

source§

fn guest_align() -> usize

source§

fn read(mem: &GuestMemory<'_>, ptr: GuestPtr<Self>) -> Result<Self, GuestError>

source§

fn write( mem: &mut GuestMemory<'_>, ptr: GuestPtr<Self>, val: Self, ) -> Result<(), GuestError>

source§

impl GuestType for i8

source§

fn guest_size() -> u32

source§

fn guest_align() -> usize

source§

fn read(mem: &GuestMemory<'_>, ptr: GuestPtr<Self>) -> Result<Self, GuestError>

source§

fn write( mem: &mut GuestMemory<'_>, ptr: GuestPtr<Self>, val: Self, ) -> Result<(), GuestError>

source§

impl GuestType for i16

source§

fn guest_size() -> u32

source§

fn guest_align() -> usize

source§

fn read(mem: &GuestMemory<'_>, ptr: GuestPtr<Self>) -> Result<Self, GuestError>

source§

fn write( mem: &mut GuestMemory<'_>, ptr: GuestPtr<Self>, val: Self, ) -> Result<(), GuestError>

source§

impl GuestType for i32

source§

fn guest_size() -> u32

source§

fn guest_align() -> usize

source§

fn read(mem: &GuestMemory<'_>, ptr: GuestPtr<Self>) -> Result<Self, GuestError>

source§

fn write( mem: &mut GuestMemory<'_>, ptr: GuestPtr<Self>, val: Self, ) -> Result<(), GuestError>

source§

impl GuestType for i64

source§

fn guest_size() -> u32

source§

fn guest_align() -> usize

source§

fn read(mem: &GuestMemory<'_>, ptr: GuestPtr<Self>) -> Result<Self, GuestError>

source§

fn write( mem: &mut GuestMemory<'_>, ptr: GuestPtr<Self>, val: Self, ) -> Result<(), GuestError>

source§

impl GuestType for u8

source§

fn guest_size() -> u32

source§

fn guest_align() -> usize

source§

fn read(mem: &GuestMemory<'_>, ptr: GuestPtr<Self>) -> Result<Self, GuestError>

source§

fn write( mem: &mut GuestMemory<'_>, ptr: GuestPtr<Self>, val: Self, ) -> Result<(), GuestError>

source§

impl GuestType for u16

source§

fn guest_size() -> u32

source§

fn guest_align() -> usize

source§

fn read(mem: &GuestMemory<'_>, ptr: GuestPtr<Self>) -> Result<Self, GuestError>

source§

fn write( mem: &mut GuestMemory<'_>, ptr: GuestPtr<Self>, val: Self, ) -> Result<(), GuestError>

source§

impl GuestType for u32

source§

fn guest_size() -> u32

source§

fn guest_align() -> usize

source§

fn read(mem: &GuestMemory<'_>, ptr: GuestPtr<Self>) -> Result<Self, GuestError>

source§

fn write( mem: &mut GuestMemory<'_>, ptr: GuestPtr<Self>, val: Self, ) -> Result<(), GuestError>

source§

impl GuestType for u64

source§

fn guest_size() -> u32

source§

fn guest_align() -> usize

source§

fn read(mem: &GuestMemory<'_>, ptr: GuestPtr<Self>) -> Result<Self, GuestError>

source§

fn write( mem: &mut GuestMemory<'_>, ptr: GuestPtr<Self>, val: Self, ) -> Result<(), GuestError>

Implementors§