Skip to main content

Step

Enum Step 

Source
pub enum Step<T> {
    Ready(T),
    NeedInput,
}
Expand description

The answer of a StreamReader call: ready, or waiting for more input.

NeedInput is not an error: the input so far is a valid beginning, and the call can be made again after feed or end_input.

§Examples

use jsonx_lib::{Event, Step, StreamReader};

let mut r = StreamReader::new();
assert_eq!(r.next_event()?, Step::NeedInput);
r.feed(b"[tr")?;
assert_eq!(r.next_event()?, Step::Ready(Some(Event::StartArray)));
assert_eq!(r.next_event()?, Step::NeedInput); // `tr` is not a value yet
r.feed(b"ue]")?;
assert_eq!(r.next_event()?.ready(), Some(Some(Event::Bool(true))));

Variants§

§

Ready(T)

The call completed with this result.

§

NeedInput

The input so far ends inside what the call needs: feed more, or end the input, and call again.

Implementations§

Source§

impl<T> Step<T>

Source

pub fn ready(self) -> Option<T>

The result, if ready.

§Examples
use jsonx_lib::Step;

assert_eq!(Step::Ready(3).ready(), Some(3));
assert_eq!(Step::<u8>::NeedInput.ready(), None);
Source

pub const fn is_ready(&self) -> bool

Whether the call completed.

§Examples
assert!(jsonx_lib::Step::Ready(()).is_ready());
Source

pub fn map<U>(self, f: impl FnOnce(T) -> U) -> Step<U>

Applies f to a ready result.

§Examples
use jsonx_lib::Step;

assert_eq!(Step::Ready(2).map(|n| n * 10), Step::Ready(20));

Trait Implementations§

Source§

impl<T: Clone> Clone for Step<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Copy> Copy for Step<T>

Source§

impl<T: Debug> Debug for Step<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: Eq> Eq for Step<T>

Source§

impl<T: Hash> Hash for Step<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq> PartialEq for Step<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for Step<T>

Auto Trait Implementations§

§

impl<T> Forget for Step<T>

§

impl<T> Freeze for Step<T>
where T: Freeze,

§

impl<T> Move for Step<T>

§

impl<T> RefUnwindSafe for Step<T>
where T: RefUnwindSafe,

§

impl<T> Send for Step<T>
where T: Send,

§

impl<T> Sync for Step<T>
where T: Sync,

§

impl<T> Unpin for Step<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Step<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Step<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.