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>
impl<'data, 'tokens, E> ObjectReader<'data, 'tokens, E>
sourcepub fn json(&self) -> JsonObjectBuilder<'data, 'tokens, E>
pub fn json(&self) -> JsonObjectBuilder<'data, 'tokens, E>
Converts the object to its JSON representation
source§impl<'data, 'tokens, E> ObjectReader<'data, 'tokens, E>
impl<'data, 'tokens, E> ObjectReader<'data, 'tokens, E>
sourcepub fn new(tape: &'tokens TextTape<'data>, encoding: E) -> Self
pub fn new(tape: &'tokens TextTape<'data>, encoding: E) -> Self
Create a new object reader from parsed data with encoded strings
sourcepub fn tokens_len(&self) -> usize
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);
sourcepub fn deserialize<T>(&self) -> Result<T, Error>where
T: Deserialize<'data>,
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() });
sourcepub fn fields_len(&self) -> usize
pub fn fields_len(&self) -> usize
Return the number of key value pairs that the object contains.
sourcepub fn fields(&self) -> FieldsIter<'data, 'tokens, E> ⓘ
pub fn fields(&self) -> FieldsIter<'data, 'tokens, E> ⓘ
Iterator over fields as they appear in the object
See FieldsIter for a worked example
sourcepub fn field_groups(&self) -> FieldGroupsIter<'data, 'tokens, E> ⓘ
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>
impl<'data, 'tokens, E: Clone> Clone for ObjectReader<'data, 'tokens, E>
source§fn clone(&self) -> ObjectReader<'data, 'tokens, E>
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more