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

Allow the tape to be used in a standard serde::Deserialize #366

Closed
19 changes: 17 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,8 @@ impl<'de> Deserializer<'de> {
}

/// Fills the tape without creating a serializer, this function poses
/// lifetime chalanges and can be frustrating, howver when it is
/// usable it allows a allocation free (armotized) parsing of JSON
/// lifetime challenges and can be frustrating, however when it is
/// usable it allows a allocation free (amortized) parsing of JSON
///
/// # Errors
///
Expand Down Expand Up @@ -922,6 +922,21 @@ impl<'de> Deserializer<'de> {
Ok(Self { tape, idx: 0 })
}

/// Creates a deserializer from a Tape.
///
/// # Safety
/// The tape is not checked for correctness. The deserializer is only
/// guaranteed to operate correctly if the tape came from a previous
/// Deserializer (e.g. from one ot the [`crate::to_tape()`] functions), and has
/// not been modified.
#[must_use]
pub unsafe fn from_tape(tape: Tape<'de>) -> Self {
Self {
tape: tape.0,
idx: 0,
}
}

#[cfg(feature = "serde_impl")]
#[cfg_attr(not(feature = "no-inline"), inline)]
fn skip(&mut self) {
Expand Down
Loading