Struct jomini::text::ObjectReader

source ·
pub struct ObjectReader<'data, 'tokens, E> { /* private fields */ }
Expand description

A reader for objects

Implementations§

source§

impl<'data, 'tokens, E> ObjectReader<'data, 'tokens, E>
where E: Encoding + Clone,

source

pub fn json(&self) -> JsonObjectBuilder<'data, 'tokens, E>

Converts the object to its JSON representation

source§

impl<'data, 'tokens, E> ObjectReader<'data, 'tokens, E>
where E: Encoding + Clone,

source

pub fn new(tape: &'tokens TextTape<'data>, encoding: E) -> Self

Create a new object reader from parsed data with encoded strings

source

pub fn tokens_len(&self) -> usize

Return the number of tokens contained within the object

use jomini::TextTape;

let tape = TextTape::from_slice(b"obj={1} foo=bar")?;
let reader = tape.windows1252_reader();
assert_eq!(reader.tokens_len(), 6);
source

pub fn deserialize<T>(&self) -> Result<T, Error>
where T: Deserialize<'data>,

Deserialize from the object reader

use jomini::TextTape;
use serde::Deserialize;

#[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct Obj {
  foo: String,
}

let tape = TextTape::from_slice(b"obj={foo=bar}")?;
let reader = tape.windows1252_reader();
let mut fields = reader.fields();
let (_, _, obj_value) = fields.next().unwrap();
let obj_reader = obj_value.read_object().unwrap();
let result: Obj = obj_reader.deserialize().unwrap();
assert_eq!(result, Obj { foo: "bar".to_string() });
source

pub fn fields_len(&self) -> usize

Return the number of key value pairs that the object contains.

source

pub fn fields(&self) -> FieldsIter<'data, 'tokens, E>

Iterator over fields as they appear in the object

See FieldsIter for a worked example

source

pub fn field_groups(&self) -> FieldGroupsIter<'data, 'tokens, E>

Iterator over fields that are grouped by key

See FieldGroupsIter for a worked example

Trait Implementations§

source§

impl<'data, 'tokens, E: Clone> Clone for ObjectReader<'data, 'tokens, E>

source§

fn clone(&self) -> ObjectReader<'data, 'tokens, E>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'data, 'tokens, E: Debug> Debug for ObjectReader<'data, 'tokens, E>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'data, 'tokens, E> Freeze for ObjectReader<'data, 'tokens, E>
where E: Freeze,

§

impl<'data, 'tokens, E> RefUnwindSafe for ObjectReader<'data, 'tokens, E>
where E: RefUnwindSafe,

§

impl<'data, 'tokens, E> Send for ObjectReader<'data, 'tokens, E>
where E: Send,

§

impl<'data, 'tokens, E> Sync for ObjectReader<'data, 'tokens, E>
where E: Sync,

§

impl<'data, 'tokens, E> Unpin for ObjectReader<'data, 'tokens, E>
where E: Unpin,

§

impl<'data, 'tokens, E> UnwindSafe for ObjectReader<'data, 'tokens, E>
where E: 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.