[][src]Enum ffimage::packed::dynamic::MemoryBuffer

pub enum MemoryBuffer {
    U8(Vec<u8>),
    U16(Vec<u16>),
}

Runtime memory buffer

Variants

U8(Vec<u8>)
U16(Vec<u16>)

Implementations

impl MemoryBuffer[src]

pub fn as_slice<T: 'static>(&self) -> Option<&[T]>[src]

Returns the slice representation of a memory buffer

It is ensured that only the proper type representation can be cast from the underlying buffer. If, for example, you were to call the method on a U16 buffer and try to get a u8 slice reference, the function would return None instead.

Example

use std::convert::TryFrom;
use ffimage::packed::dynamic::{MemoryBuffer, StorageType};

let mut mem: Vec<u8> = vec![0; 12];
let buf = MemoryBuffer::try_from(mem)
    .expect("Failed to wrap memory region");

let slice: &[u8] = buf.as_slice()
    .expect("Failed to cast memory buffer");

pub fn as_mut_slice<T: 'static>(&mut self) -> Option<&mut [T]>[src]

Returns the mutable slice representation of a memory buffer

It is ensured that only the proper type representation can be cast from the underlying buffer. If, for example, you were to call the method on a U16 buffer and try to get a u8 slice reference, the function would return None instead.

Example

use std::convert::TryFrom;
use ffimage::packed::dynamic::{MemoryBuffer, StorageType};

let mut mem: Vec<u8> = vec![0; 12];
let mut buf = MemoryBuffer::try_from(mem)
    .expect("Failed to wrap memory region");

let slice: &mut [u8] = buf.as_mut_slice()
    .expect("Failed to cast memory buffer");

pub fn len(&self) -> usize[src]

Returns the number of elements in the buffer

pub fn is_empty(&self) -> bool[src]

Returns true if there are no elements in the buffer

Trait Implementations

impl<'a, '_> From<&'_ MemoryView<'a>> for MemoryBuffer[src]

impl<T: 'static> TryFrom<Vec<T>> for MemoryBuffer[src]

type Error = ()

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.