pub struct WriteSerializer<W: Write> { /* private fields */ }
Expand description

Wraps a type that implements io::Write and equips it with Serializer.

Examples

use rkyv::ser::{serializers::WriteSerializer, Serializer};

let mut serializer = WriteSerializer::new(Vec::new());
assert_eq!(serializer.pos(), 0);
serializer.write(&[0u8, 1u8, 2u8, 3u8]);
assert_eq!(serializer.pos(), 4);
let buf = serializer.into_inner();
assert_eq!(buf.len(), 4);
assert_eq!(buf, vec![0u8, 1u8, 2u8, 3u8]);

Implementations§

source§

impl<W: Write> WriteSerializer<W>

source

pub fn new(inner: W) -> Self

Creates a new serializer from a writer.

source

pub fn with_pos(inner: W, pos: usize) -> Self

Creates a new serializer from a writer, and assumes that the underlying writer is currently at the given position.

source

pub fn into_inner(self) -> W

Consumes the serializer and returns the internal writer used to create it.

Trait Implementations§

source§

impl<W: Debug + Write> Debug for WriteSerializer<W>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<W: Write> Fallible for WriteSerializer<W>

§

type Error = Error

The error produced by any failing methods.
source§

impl<W: Write> Serializer for WriteSerializer<W>

source§

fn pos(&self) -> usize

Returns the current position of the serializer.
source§

fn write(&mut self, bytes: &[u8]) -> Result<(), Self::Error>

Attempts to write the given bytes to the serializer.
source§

fn pad(&mut self, padding: usize) -> Result<(), Self::Error>

Advances the given number of bytes as padding.
source§

fn align(&mut self, align: usize) -> Result<usize, Self::Error>

Aligns the position of the serializer to the given alignment.
source§

fn align_for<T>(&mut self) -> Result<usize, Self::Error>

Aligns the position of the serializer to be suitable to write the given type.
source§

unsafe fn resolve_aligned<T: Archive + ?Sized>( &mut self, value: &T, resolver: T::Resolver ) -> Result<usize, Self::Error>

Resolves the given value with its resolver and writes the archived type. Read more
source§

fn serialize_value<T: Serialize<Self>>( &mut self, value: &T ) -> Result<usize, Self::Error>

Archives the given object and returns the position it was archived at.
source§

unsafe fn resolve_unsized_aligned<T: ArchiveUnsized + ?Sized>( &mut self, value: &T, to: usize, metadata_resolver: T::MetadataResolver ) -> Result<usize, Self::Error>

Resolves the given reference with its resolver and writes the archived reference. Read more
source§

fn serialize_unsized_value<T: SerializeUnsized<Self> + ?Sized>( &mut self, value: &T ) -> Result<usize, Self::Error>

Archives a reference to the given object and returns the position it was archived at.

Auto Trait Implementations§

§

impl<W> RefUnwindSafe for WriteSerializer<W>
where W: RefUnwindSafe,

§

impl<W> Send for WriteSerializer<W>
where W: Send,

§

impl<W> Sync for WriteSerializer<W>
where W: Sync,

§

impl<W> Unpin for WriteSerializer<W>
where W: Unpin,

§

impl<W> UnwindSafe for WriteSerializer<W>
where W: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

source§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.