Struct struson::reader::simple::ArrayReader
source · pub struct ArrayReader<'a, J: JsonReader> { /* private fields */ }Available on crate feature
experimental only.Expand description
Reader for an arbitrary amount of JSON array items
This struct is used by ValueReader::read_array.
Implementations§
source§impl<J: JsonReader> ArrayReader<'_, J>
impl<J: JsonReader> ArrayReader<'_, J>
sourcepub fn has_next(&mut self) -> Result<bool, ReaderError>
pub fn has_next(&mut self) -> Result<bool, ReaderError>
Checks if there is a next item in the JSON array, without consuming it
Returns true if there is a next item, false otherwise. This method can be
useful as condition of a while loop when processing a JSON array of unknown size.
§Examples
let json_reader = SimpleJsonReader::new("[1, 2]".as_bytes());
json_reader.read_array(|array_reader| {
while array_reader.has_next()? {
let value = array_reader.read_number_as_string()?;
println!("{value}");
}
Ok(())
})?;Trait Implementations§
source§impl<'a, J: Debug + JsonReader> Debug for ArrayReader<'a, J>
impl<'a, J: Debug + JsonReader> Debug for ArrayReader<'a, J>
source§impl<J: JsonReader> ValueReader<J> for &mut ArrayReader<'_, J>
impl<J: JsonReader> ValueReader<J> for &mut ArrayReader<'_, J>
source§fn peek_value(&mut self) -> Result<ValueType, ReaderError>
fn peek_value(&mut self) -> Result<ValueType, ReaderError>
Peeks at the type of the next JSON value, without consuming it
source§fn read_str<T>(
self,
f: impl FnOnce(&str) -> Result<T, Box<dyn Error>>
) -> Result<T, Box<dyn Error>>
fn read_str<T>( self, f: impl FnOnce(&str) -> Result<T, Box<dyn Error>> ) -> Result<T, Box<dyn Error>>
Consumes a JSON string value as borrowed
str Read moresource§fn read_string(self) -> Result<String, ReaderError>
fn read_string(self) -> Result<String, ReaderError>
Consumes and returns a JSON string value as owned
String Read moresource§fn read_string_with_reader<T>(
self,
f: impl FnOnce(StringValueReader<'_>) -> Result<T, Box<dyn Error>>
) -> Result<T, Box<dyn Error>>
fn read_string_with_reader<T>( self, f: impl FnOnce(StringValueReader<'_>) -> Result<T, Box<dyn Error>> ) -> Result<T, Box<dyn Error>>
source§fn read_number<T: FromStr>(self) -> Result<Result<T, T::Err>, ReaderError>
fn read_number<T: FromStr>(self) -> Result<Result<T, T::Err>, ReaderError>
Consumes and returns a JSON number value Read more
source§fn read_number_as_string(self) -> Result<String, ReaderError>
fn read_number_as_string(self) -> Result<String, ReaderError>
Consumes and returns the string representation of a JSON number value Read more
source§fn read_deserialize<'de, D: Deserialize<'de>>(
self
) -> Result<D, DeserializerError>
fn read_deserialize<'de, D: Deserialize<'de>>( self ) -> Result<D, DeserializerError>
Available on crate feature
serde only.Deserializes a Serde
Deserialize from the next value Read moresource§fn skip_value(self) -> Result<(), ReaderError>
fn skip_value(self) -> Result<(), ReaderError>
Skips the next JSON value Read more
source§fn read_array<T>(
self,
f: impl FnOnce(&mut ArrayReader<'_, J>) -> Result<T, Box<dyn Error>>
) -> Result<T, Box<dyn Error>>
fn read_array<T>( self, f: impl FnOnce(&mut ArrayReader<'_, J>) -> Result<T, Box<dyn Error>> ) -> Result<T, Box<dyn Error>>
Consumes a JSON array Read more
source§fn read_object_borrowed_names(
self,
f: impl FnMut(MemberReader<'_, J>) -> Result<(), Box<dyn Error>>
) -> Result<(), Box<dyn Error>>
fn read_object_borrowed_names( self, f: impl FnMut(MemberReader<'_, J>) -> Result<(), Box<dyn Error>> ) -> Result<(), Box<dyn Error>>
Consumes a JSON object and all of its members, reading names as borrowed
str Read moresource§fn read_object_owned_names(
self,
f: impl FnMut(String, SingleValueReader<'_, J>) -> Result<(), Box<dyn Error>>
) -> Result<(), Box<dyn Error>>
fn read_object_owned_names( self, f: impl FnMut(String, SingleValueReader<'_, J>) -> Result<(), Box<dyn Error>> ) -> Result<(), Box<dyn Error>>
Consumes a JSON object and all of its members, reading names as owned
String Read moresource§fn read_seeked<T>(
self,
path: &JsonPath,
f: impl FnOnce(SingleValueReader<'_, J>) -> Result<T, Box<dyn Error>>
) -> Result<T, Box<dyn Error>>
fn read_seeked<T>( self, path: &JsonPath, f: impl FnOnce(SingleValueReader<'_, J>) -> Result<T, Box<dyn Error>> ) -> Result<T, Box<dyn Error>>
Seeks to a value and consumes it Read more
Auto Trait Implementations§
impl<'a, J> Freeze for ArrayReader<'a, J>
impl<'a, J> !RefUnwindSafe for ArrayReader<'a, J>
impl<'a, J> Send for ArrayReader<'a, J>where
J: Send,
impl<'a, J> Sync for ArrayReader<'a, J>where
J: Sync,
impl<'a, J> Unpin for ArrayReader<'a, J>
impl<'a, J> !UnwindSafe for ArrayReader<'a, J>
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