Skip to main content

StreamDeserializer

Struct StreamDeserializer 

Source
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 stream

Implementations§

Source§

impl<'de, T> StreamDeserializer<'de, T>
where T: Deserialize<'de>,

Source

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 - true for binary format, false for text format.
Source

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 type T.
§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> 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.