[][src]Struct rkyv::ArchiveBuffer

pub struct ArchiveBuffer<T> { /* fields omitted */ }

Wraps a byte buffer and writes into it.

Common uses include archiving in #[no_std] environments and archiving small objects without allocating.

Examples

use rkyv::{Aligned, Archive, ArchiveBuffer, Archived, WriteExt};

#[derive(Archive)]
enum Event {
    Spawn,
    Speak(String),
    Die,
}
 
fn main() {
    let mut writer = ArchiveBuffer::new(Aligned([0u8; 256]));
    let pos = writer.archive(&Event::Speak("Help me!".to_string()))
        .expect("failed to archive event");
    let buf = writer.into_inner();
    let archived = unsafe { &*buf.as_ref().as_ptr().add(pos).cast::<Archived<Event>>() };
    if let Archived::<Event>::Speak(message) = archived {
        assert_eq!(message.as_str(), "Help me!");
    } else {
        panic!("archived event was of the wrong type");
    }
}

Implementations

impl<T> ArchiveBuffer<T>[src]

pub fn new(inner: T) -> Self[src]

Creates a new archive buffer from a byte buffer.

pub fn with_pos(inner: T, pos: usize) -> Self[src]

Creates a new archive buffer from a byte buffer. The buffer will start writing at the given position, but the buffer must contain all bytes (otherwise the alignments of types may not be correct).

pub fn into_inner(self) -> T[src]

Consumes the buffer and returns the internal buffer used to create it.

Trait Implementations

impl<T: AsRef<[u8]> + AsMut<[u8]>> Write for ArchiveBuffer<T>[src]

type Error = ArchiveBufferError

The errors that may occur while writing.

Auto Trait Implementations

impl<T> RefUnwindSafe for ArchiveBuffer<T> where
    T: RefUnwindSafe

impl<T> Send for ArchiveBuffer<T> where
    T: Send

impl<T> Sync for ArchiveBuffer<T> where
    T: Sync

impl<T> Unpin for ArchiveBuffer<T> where
    T: Unpin

impl<T> UnwindSafe for ArchiveBuffer<T> where
    T: UnwindSafe

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.

impl<W> WriteExt for W where
    W: Write + ?Sized
[src]