[−][src]Struct rkyv::ArchiveBuffer
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, archived_value, WriteExt}; #[derive(Archive)] enum Event { Spawn, Speak(String), Die, } 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 { archived_value::<Event, _>(&buf, 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> 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
Auto Trait Implementations
impl<T> RefUnwindSafe for ArchiveBuffer<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for ArchiveBuffer<T> where
T: Send,
T: Send,
impl<T> Sync for ArchiveBuffer<T> where
T: Sync,
T: Sync,
impl<T> Unpin for ArchiveBuffer<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for ArchiveBuffer<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<W> WriteExt for W where
W: Write + ?Sized,
[src]
W: Write + ?Sized,
pub fn align(&mut self, align: usize) -> Result<usize, Self::Error>
[src]
pub fn align_for<T>(&mut self) -> Result<usize, Self::Error>
[src]
pub unsafe fn resolve_aligned<T: ?Sized, R: Resolve<T>>(
&mut self,
value: &T,
resolver: R
) -> Result<usize, Self::Error>
[src]
&mut self,
value: &T,
resolver: R
) -> Result<usize, Self::Error>
pub fn archive<T: Archive>(&mut self, value: &T) -> Result<usize, Self::Error>
[src]
pub fn archive_ref<T: ArchiveRef + ?Sized>(
&mut self,
value: &T
) -> Result<usize, Self::Error>
[src]
&mut self,
value: &T
) -> Result<usize, Self::Error>