[−][src]Trait wiggle::GuestType
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
fn guest_size() -> u32
Returns the size, in bytes, of this type in the guest memory.
fn guest_align() -> usize
Returns the required alignment of this type, in bytes, for both guest and host memory.
fn read(ptr: &GuestPtr<'a, 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.
fn write(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.
Implementations on Foreign Types
impl<'a> GuestType<'a> for i8
[src]
fn guest_size() -> u32
[src]
fn guest_align() -> usize
[src]
fn read(ptr: &GuestPtr<'a, Self>) -> Result<Self, GuestError>
[src]
fn write(ptr: &GuestPtr<'_, Self>, val: Self) -> Result<(), GuestError>
[src]
impl<'a> GuestType<'a> for i16
[src]
fn guest_size() -> u32
[src]
fn guest_align() -> usize
[src]
fn read(ptr: &GuestPtr<'a, Self>) -> Result<Self, GuestError>
[src]
fn write(ptr: &GuestPtr<'_, Self>, val: Self) -> Result<(), GuestError>
[src]
impl<'a> GuestType<'a> for i32
[src]
fn guest_size() -> u32
[src]
fn guest_align() -> usize
[src]
fn read(ptr: &GuestPtr<'a, Self>) -> Result<Self, GuestError>
[src]
fn write(ptr: &GuestPtr<'_, Self>, val: Self) -> Result<(), GuestError>
[src]
impl<'a> GuestType<'a> for i64
[src]
fn guest_size() -> u32
[src]
fn guest_align() -> usize
[src]
fn read(ptr: &GuestPtr<'a, Self>) -> Result<Self, GuestError>
[src]
fn write(ptr: &GuestPtr<'_, Self>, val: Self) -> Result<(), GuestError>
[src]
impl<'a> GuestType<'a> for i128
[src]
fn guest_size() -> u32
[src]
fn guest_align() -> usize
[src]
fn read(ptr: &GuestPtr<'a, Self>) -> Result<Self, GuestError>
[src]
fn write(ptr: &GuestPtr<'_, Self>, val: Self) -> Result<(), GuestError>
[src]
impl<'a> GuestType<'a> for u8
[src]
fn guest_size() -> u32
[src]
fn guest_align() -> usize
[src]
fn read(ptr: &GuestPtr<'a, Self>) -> Result<Self, GuestError>
[src]
fn write(ptr: &GuestPtr<'_, Self>, val: Self) -> Result<(), GuestError>
[src]
impl<'a> GuestType<'a> for u16
[src]
fn guest_size() -> u32
[src]
fn guest_align() -> usize
[src]
fn read(ptr: &GuestPtr<'a, Self>) -> Result<Self, GuestError>
[src]
fn write(ptr: &GuestPtr<'_, Self>, val: Self) -> Result<(), GuestError>
[src]
impl<'a> GuestType<'a> for u32
[src]
fn guest_size() -> u32
[src]
fn guest_align() -> usize
[src]
fn read(ptr: &GuestPtr<'a, Self>) -> Result<Self, GuestError>
[src]
fn write(ptr: &GuestPtr<'_, Self>, val: Self) -> Result<(), GuestError>
[src]
impl<'a> GuestType<'a> for u64
[src]
fn guest_size() -> u32
[src]
fn guest_align() -> usize
[src]
fn read(ptr: &GuestPtr<'a, Self>) -> Result<Self, GuestError>
[src]
fn write(ptr: &GuestPtr<'_, Self>, val: Self) -> Result<(), GuestError>
[src]
impl<'a> GuestType<'a> for u128
[src]
fn guest_size() -> u32
[src]
fn guest_align() -> usize
[src]
fn read(ptr: &GuestPtr<'a, Self>) -> Result<Self, GuestError>
[src]
fn write(ptr: &GuestPtr<'_, Self>, val: Self) -> Result<(), GuestError>
[src]
impl<'a> GuestType<'a> for f32
[src]
fn guest_size() -> u32
[src]
fn guest_align() -> usize
[src]
fn read(ptr: &GuestPtr<'a, Self>) -> Result<Self, GuestError>
[src]
fn write(ptr: &GuestPtr<'_, Self>, val: Self) -> Result<(), GuestError>
[src]
impl<'a> GuestType<'a> for f64
[src]
fn guest_size() -> u32
[src]
fn guest_align() -> usize
[src]
fn read(ptr: &GuestPtr<'a, Self>) -> Result<Self, GuestError>
[src]
fn write(ptr: &GuestPtr<'_, Self>, val: Self) -> Result<(), GuestError>
[src]
Implementors
impl<'a, T> GuestType<'a> for GuestPtr<'a, [T]> where
T: GuestType<'a>,
[src]
T: GuestType<'a>,