pub struct StreamDeserializer<'de, T> { /* private fields */ }Expand description
A streaming deserializer that reads a sequence of YSON values from an input buffer.
In many YSON use cases, data is provided as a sequence of top-level values
optionally separated by semicolons (e.g., 1; 2; 3;). StreamDeserializer
allows you to lazily iterate through these values without having to wrap
them in a list [...].
§Examples
use ytsaurus_yson::de::StreamDeserializer;
let input = b"1; 2; 3";
let mut stream = StreamDeserializer::<i32>::new(input, false);
assert_eq!(stream.next_item().unwrap(), Some(1));
assert_eq!(stream.next_item().unwrap(), Some(2));
assert_eq!(stream.next_item().unwrap(), Some(3));
assert_eq!(stream.next_item().unwrap(), None); // End of streamImplementations§
Source§impl<'de, T> StreamDeserializer<'de, T>where
T: Deserialize<'de>,
impl<'de, T> StreamDeserializer<'de, T>where
T: Deserialize<'de>,
Sourcepub fn new(input: &'de [u8], is_binary: bool) -> Self
pub fn new(input: &'de [u8], is_binary: bool) -> Self
Creates a new StreamDeserializer from the given byte slice.
§Arguments
input- The raw byte slice containing a sequence of YSON values.is_binary-truefor binary format,falsefor text format.
Sourcepub fn next_item(&mut self) -> Result<Option<T>, YsonError>
pub fn next_item(&mut self) -> Result<Option<T>, YsonError>
Deserializes the next item in the stream.
§Returns
Ok(Some(T))if a value was successfully deserialized.Ok(None)if the end of the input was reached.Err(YsonError)if a parsing error occurred or if the data doesn’t match typeT.
§Errors
This method will return an error if:
- The YSON syntax is malformed.
- An item separator (semicolon) is missing where one is expected.
- The input ends prematurely after a separator.
Auto Trait Implementations§
impl<'de, T> Freeze for StreamDeserializer<'de, T>
impl<'de, T> RefUnwindSafe for StreamDeserializer<'de, T>where
T: RefUnwindSafe,
impl<'de, T> Send for StreamDeserializer<'de, T>where
T: Send,
impl<'de, T> Sync for StreamDeserializer<'de, T>where
T: Sync,
impl<'de, T> Unpin for StreamDeserializer<'de, T>where
T: Unpin,
impl<'de, T> UnsafeUnpin for StreamDeserializer<'de, T>
impl<'de, T> UnwindSafe for StreamDeserializer<'de, T>where
T: 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