Struct rxml::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§

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.

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.

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.

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.

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§

Create an encoder from a TrackNamespace instance.

Use your own custom namespace strategy.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.