Encoder

Struct Encoder 

Source
pub struct Encoder<T> { /* private fields */ }
Expand description

Encodes XML into buffers.

Encoders are stateful. They can only be used to encode a single XML document and have then to be disposed.

use rxml::{Encoder, Item, XmlVersion};
use bytes::BytesMut;

let mut enc = Encoder::new();
let mut buf = BytesMut::new();
enc.encode(Item::XmlDeclaration(XmlVersion::V1_0), &mut buf);
assert_eq!(&buf[..], b"<?xml version='1.0' encoding='utf-8'?>\n");

Implementations§

Source§

impl Encoder<SimpleNamespaces>

Source

pub fn new() -> Self

Create a new default encoder.

This encoder uses the SimpleNamespaces strategy, which is not optimal with respect to the number of bytes written, but has reduced memory cost.

Source§

impl<T: TrackNamespace> Encoder<T>

Source

pub fn ns_tracker(&self) -> &T

Access the namespace tracking implementation.

Source

pub fn ns_tracker_mut(&mut self) -> &mut T

Access the namespace tracking implementation, mutably.

Source

pub fn encode<O: BufMut>( &mut self, item: Item<'_>, output: &mut O, ) -> Result<()>

Encode a single item into a buffer.

There is no requirement for the buffer to be the same for subsequent calls to this function. This allows users to use small, but long-lived, buffers for serialization before sending data over the network, for instance.

Source

pub fn encode_into_bytes( &mut self, item: Item<'_>, output: &mut BytesMut, ) -> Result<()>

Encode a single item into a BytesMut.

This might have a slight performance advantage over encode in some scenarios, as it might be able to give the BytesMut a heads up about required space, thus avoiding frequent reallocations.

There is no requirement for the buffer to be the same for subsequent calls to this function. This allows users to use small, but long-lived, buffers for serialization before sending data over the network, for instance.

Source

pub fn encode_event<O: BufMut>( &mut self, ev: &Event, output: &mut O, ) -> Result<()>

Encode a single event into a buffer.

This internally decomposes the event into multiple items and then encodes these into the given buffer using encode.

Source

pub fn encode_event_into_bytes( &mut self, ev: &Event, output: &mut BytesMut, ) -> Result<()>

Encode a single event into a BytesMut.

This internally decomposes the event into multiple items and then encodes these into the given buffer using encode_into_bytes.

Trait Implementations§

Source§

impl<T: Default> Default for Encoder<T>

Source§

fn default() -> Encoder<T>

Returns the “default value” for a type. Read more
Source§

impl<T: TrackNamespace> From<T> for Encoder<T>

Source§

fn from(ns: T) -> Self

Create an encoder from a TrackNamespace instance.

Use your own custom namespace strategy.

Auto Trait Implementations§

§

impl<T> Freeze for Encoder<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Encoder<T>
where T: RefUnwindSafe,

§

impl<T> Send for Encoder<T>
where T: Send,

§

impl<T> Sync for Encoder<T>
where T: Sync,

§

impl<T> Unpin for Encoder<T>
where T: Unpin,

§

impl<T> UnwindSafe for Encoder<T>
where T: 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> 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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.