Skip to content

Commit d9ab038

Browse files
committed
Add deserialize method to tape
Signed-off-by: Heinz N. Gies <heinz@licenser.net>
1 parent 6d197e2 commit d9ab038

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/value/tape.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ impl<'input> Tape<'input> {
3333
// so we can safely change the lifetime of the tape to 'new
3434
unsafe { std::mem::transmute(self) }
3535
}
36+
37+
/// Deserializes the tape into a type that implements `serde::Deserialize`
38+
/// # Errors
39+
/// Returns an error if the deserialization fails
40+
#[cfg(feature = "serde")]
41+
pub fn deserialize<T>(self) -> crate::Result<T>
42+
where
43+
T: serde::Deserialize<'input>,
44+
{
45+
use crate::Deserializer;
46+
47+
let mut deserializer = Deserializer {
48+
tape: self.0,
49+
idx: 0,
50+
};
51+
52+
T::deserialize(&mut deserializer)
53+
}
3654
}
3755

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

0 commit comments

Comments
 (0)