Skip to main content

Decoder

Struct Decoder 

Source
pub struct Decoder<R> { /* private fields */ }
Expand description

Reads one property-list document from a reader, auto-detecting its Format.

The first decode call buffers the reader to end of input; decoding works over that buffer, so the reader needs no Seek bound and repeated decode calls re-run detection over the same bytes, returning equal values for every format. Decode memory is proportional to the input size.

§Examples

use apple_plist::{Decoder, Format};

let mut decoder = Decoder::new(&b"(1,2,3)"[..]);
assert_eq!(decoder.format(), None);
let value = decoder.decode_value()?;
assert_eq!(value.as_array().map(Vec::len), Some(3));
assert_eq!(decoder.format(), Some(Format::OpenStep));

Implementations§

Source§

impl<R: Read> Decoder<R>

Source

pub const fn new(reader: R) -> Self

Creates a decoder over reader; no I/O happens until the first decode call.

Source

pub const fn format(&self) -> Option<Format>

The format detected by the most recent successful parse, or None if no parse has succeeded yet.

The format is recorded before the value maps into the target type, so a failed decode whose document parsed still reports it.

Source

pub fn decode_value(&mut self) -> Result<Value>

Decodes the buffered document into a Value tree.

§Errors

Returns Error::Io when buffering the reader fails, and otherwise whatever the detection ladder reports: Error::Parse for malformed documents, Error::MaxDepthExceeded for hostile nesting, and Error::InvalidPlist / Error::FeatureDisabled in builds whose codec features are compiled out.

Source

pub fn decode<T: DeserializeOwned>(&mut self) -> Result<T>

Decodes the buffered document into any DeserializeOwned type.

When detection reports Format::OpenStep — a format that can only store strings — the mapping coerces strings into requested integers, floats, booleans, and dates, the codec’s lax mode.

§Errors

Everything decode_value can return, plus the mapping failures of from_value.

§Examples
use apple_plist::Decoder;

let document = b"<?xml version=\"1.0\"?><plist><integer>42</integer></plist>";
let answer: i64 = Decoder::new(&document[..]).decode()?;
assert_eq!(answer, 42);

Trait Implementations§

Source§

impl<R> Debug for Decoder<R>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R> Freeze for Decoder<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for Decoder<R>
where R: RefUnwindSafe,

§

impl<R> Send for Decoder<R>
where R: Send,

§

impl<R> Sync for Decoder<R>
where R: Sync,

§

impl<R> Unpin for Decoder<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for Decoder<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for Decoder<R>
where R: 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.