Skip to content

Commit

Permalink
Deserializer: Extract from_bytes() constructor fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 authored Dec 18, 2024
1 parent 6ff055a commit 4591f76
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn from_bytes<'de, T>(input: &'de [u8]) -> Result<T, Error>
where
T: de::Deserialize<'de>,
{
T::deserialize(Deserializer::new(parse(input)))
T::deserialize(Deserializer::from_bytes(input))
}

/// Deserializes a `application/x-www-form-urlencoded` value from a `&str`.
Expand Down Expand Up @@ -97,6 +97,11 @@ impl<'de> Deserializer<'de> {
pub fn new(parse: UrlEncodedParse<'de>) -> Self {
Deserializer { inner: parse }
}

/// Returns a new `Deserializer` from a `&[u8]`.
pub fn from_bytes(input: &'de [u8]) -> Self {
Self::new(parse(input))
}
}

impl<'de> de::Deserializer<'de> for Deserializer<'de> {
Expand Down

0 comments on commit 4591f76

Please sign in to comment.