Skip to content

Commit

Permalink
Add deserialize method to tape
Browse files Browse the repository at this point in the history
Signed-off-by: Heinz N. Gies <[email protected]>
  • Loading branch information
Licenser committed Aug 27, 2024
1 parent 6d197e2 commit d9ab038
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/value/tape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ impl<'input> Tape<'input> {
// so we can safely change the lifetime of the tape to 'new
unsafe { std::mem::transmute(self) }
}

/// Deserializes the tape into a type that implements `serde::Deserialize`
/// # Errors
/// Returns an error if the deserialization fails
#[cfg(feature = "serde")]
pub fn deserialize<T>(self) -> crate::Result<T>
where
T: serde::Deserialize<'input>,
{
use crate::Deserializer;

let mut deserializer = Deserializer {
tape: self.0,
idx: 0,
};

T::deserialize(&mut deserializer)
}
}

/// Wrapper around the tape that allows interaction via a `Value`-like API.
Expand Down

0 comments on commit d9ab038

Please sign in to comment.