Struct xt::Translator

source ·
pub struct Translator<W>(/* private fields */)
where
    W: Write;
Expand description

Translates multiple inputs to a single serialized output.

A Translator accepts both slice and reader input. See translate_slice and translate_reader for considerations associated with each kind of source.

When a Translator is used more than once to translate different inputs, it outputs the logical concatenation of all documents from all inputs as if they had been presented in a single input. When translating to a format without multi-document support, translation will fail if the translator encounters more than one document in the first input, or if the translator is called a second time with another input.

Implementations§

source§

impl<W> Translator<W>
where W: Write,

source

pub fn new(output: W, to: Format) -> Translator<W>

Creates a translator that produces output in the given format.

source

pub fn translate_slice( &mut self, input: &[u8], from: Option<Format> ) -> Result<()>

Translates the contents of a single input slice to a different format.

Slice inputs are typically more efficient to translate than reader inputs, but require all input to be available in memory in advance. For unbounded streams like standard input or non-regular files, consider using translate_reader rather than reading the entire stream into memory manually.

When from is None, xt will attempt to detect the input format from the input itself.

source

pub fn translate_reader<R>( &mut self, input: R, from: Option<Format> ) -> Result<()>
where R: Read,

Translates the contents of a single reader to a different format.

Reader inputs enable streaming translation for most formats, allowing xt to translate documents as they appear in the stream without buffering more than one document in memory at a time. When translating from a format that does not support streaming, xt will automatically read the entire input into memory before starting translation.

When from is None, xt will attempt to detect the input format from the input itself. The current format detection implementation does this by fully reading the contents of a single document into memory before starting translation.

source

pub fn flush(&mut self) -> Result<()>

Flushes the underlying writer.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<W> UnwindSafe for Translator<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> 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>,

§

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.