Struct rkyv::ser::serializers::BufferSerializer[][src]

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

Wraps a byte buffer and equips it with Serializer.

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

Examples

use rkyv::{
    archived_value,
    ser::{Serializer, serializers::BufferSerializer},
    Aligned,
    Archive,
    Archived,
    Serialize,
};

#[derive(Archive, Serialize)]
enum Event {
    Spawn,
    Speak(String),
    Die,
}

let mut serializer = BufferSerializer::new(Aligned([0u8; 256]));
let pos = serializer.serialize_value(&Event::Speak("Help me!".to_string()))
    .expect("failed to archive event");
let buf = serializer.into_inner();
let archived = unsafe { archived_value::<Event>(buf.as_ref(), pos) };
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> BufferSerializer<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]>> Fallible for BufferSerializer<T>[src]

type Error = BufferSerializerError

The error produced by any failing methods

impl<T: AsRef<[u8]> + AsMut<[u8]>> SeekSerializer for BufferSerializer<T>[src]

impl<T: AsRef<[u8]> + AsMut<[u8]>> Serializer for BufferSerializer<T>[src]

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

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

impl<T> ArchivePointee for T[src]

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.

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> Pointee for T[src]

type Metadata = ()

The type for metadata in pointers and references to Self.

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.