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>
impl<'de, T: Deserialize<'de>> OwnedDriver<'de, T>
Sourcepub fn new() -> OwnedDriver<'de, T>
pub fn new() -> OwnedDriver<'de, T>
Creates a driver for a value.
Source§impl<'de, T> OwnedDriver<'de, T>
impl<'de, T> OwnedDriver<'de, T>
Sourcepub fn with<R, F>(&mut self, f: F) -> Rwhere
F: for<'a> FnOnce(&mut DeserializeDriver<'a, 'de>) -> R,
pub fn with<R, F>(&mut self, f: F) -> Rwhere
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.
Sourcepub fn finish(self) -> Result<T, Error>
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>
impl<'de, T: Deserialize<'de>> Default for OwnedDriver<'de, T>
Source§fn default() -> OwnedDriver<'de, T>
fn default() -> OwnedDriver<'de, T>
Returns the “default value” for a type. Read more
Source§impl<'de, T> Drop for OwnedDriver<'de, T>
impl<'de, T> Drop for OwnedDriver<'de, T>
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>
impl<'de, T> Send for OwnedDriver<'de, T>
impl<'de, T> UnsafeUnpin for OwnedDriver<'de, T>where
NonuniqueBox<Option<T>>: UnsafeUnpin,
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