Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deserialize method to tape #386

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "simd-json"
version = "0.14.0-rc.2"
version = "0.14.0-rc.3"
authors = ["Heinz N. Gies <[email protected]>", "Sunny Gleason"]
edition = "2021"
exclude = ["data/*", "fuzz/*"]
Expand Down
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
Loading