Skip to main content

OwnedDriver

Struct OwnedDriver 

Source
pub struct OwnedDriver<'de, T> { /* private fields */ }
Expand description

A DeserializeDriver which owns the value it deserializes.

A DeserializeDriver borrows the slot of the value it deserializes, which means that it cannot be held together with the slot, for instance in a struct that deserializes a value from input which arrives over time. This bundles a driver with its slot. The driver is lent out with with and the value is taken with finish:

use deser::de::OwnedDriver;
use deser::Event;

let mut driver = OwnedDriver::<Vec<u32>>::new();
driver.with(|driver| driver.emit(Event::seq_start())).unwrap();
// ... later, when more input arrived
driver.with(|driver| {
    driver.emit(1u64)?;
    driver.emit(Event::SeqEnd)
}).unwrap();
assert_eq!(driver.finish().unwrap(), [1]);

Implementations§

Source§

impl<'de, T: Deserialize<'de>> OwnedDriver<'de, T>

Source

pub fn new() -> OwnedDriver<'de, T>

Creates a driver for a value.

Source§

impl<'de, T> OwnedDriver<'de, T>

Source

pub fn with<R, F>(&mut self, f: F) -> R
where F: for<'a> FnOnce(&mut DeserializeDriver<'a, 'de>) -> R,

Invokes a function with the driver.

The function has to accept a driver of any lifetime which ensures that it cannot keep the driver or replace it.

Source

pub fn driver(&self) -> &DeserializeDriver<'_, 'de>

Returns a reference to the driver.

Source

pub fn finish(self) -> Result<T, Error>

Finishes the deserialization and returns the value.

Fails with ErrorKind::EndOfFile if the value is incomplete.

Trait Implementations§

Source§

impl<'de, T: Deserialize<'de>> Default for OwnedDriver<'de, T>

Source§

fn default() -> OwnedDriver<'de, T>

Returns the “default value” for a type. Read more
Source§

impl<'de, T> Drop for OwnedDriver<'de, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'de, T> !RefUnwindSafe for OwnedDriver<'de, T>

§

impl<'de, T> !Sync for OwnedDriver<'de, T>

§

impl<'de, T> !Unpin for OwnedDriver<'de, T>

§

impl<'de, T> !UnwindSafe for OwnedDriver<'de, T>

§

impl<'de, T> Freeze for OwnedDriver<'de, T>
where NonuniqueBox<Option<T>>: Freeze,

§

impl<'de, T> Send for OwnedDriver<'de, T>
where NonuniqueBox<Option<T>>: Send,

§

impl<'de, T> UnsafeUnpin for OwnedDriver<'de, T>
where NonuniqueBox<Option<T>>: UnsafeUnpin,

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 = !

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.