Skip to content

Commit

Permalink
Add Deserializer::new to crate a new deserializer, and public deser…
Browse files Browse the repository at this point in the history
…ializer. (#91)

* Add `Deserializer::new` to crate a new deserializer, and public deserializer.

* Update mod.rs

Co-authored-by: Paul Hansen <mail@paul.rs>

---------

Co-authored-by: Paul Hansen <mail@paul.rs>
  • Loading branch information
huacnlee and paul-hansen committed Apr 7, 2024
1 parent 9628c7e commit 8283aaf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/de/mod.rs
Expand Up @@ -189,7 +189,7 @@ pub fn from_str<'de, T: de::Deserialize<'de>>(input: &'de str) -> Result<T> {
/// A deserializer for the querystring format.
///
/// Supported top-level outputs are structs and maps.
pub(crate) struct QsDeserializer<'a> {
pub struct QsDeserializer<'a> {
iter: IntoIter<Cow<'a, str>, Level<'a>>,
value: Option<Level<'a>>,
}
Expand All @@ -213,9 +213,13 @@ impl<'a> QsDeserializer<'a> {
}

/// Returns a new `QsDeserializer<'a>`.
fn with_config(config: &Config, input: &'a [u8]) -> Result<Self> {
pub fn with_config(config: &Config, input: &'a [u8]) -> Result<Self> {
parse::Parser::new(input, config.max_depth(), config.strict).as_deserializer()
}

pub fn new(input: &'a [u8]) -> Result<Self> {
Self::with_config(&Config::default(), input)
}
}

impl<'de> de::Deserializer<'de> for QsDeserializer<'de> {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Expand Up @@ -206,10 +206,10 @@ mod error;
mod ser;
pub(crate) mod utils;

#[doc(inline)]
pub use de::Config;
#[doc(inline)]
pub use de::{from_bytes, from_str};
#[doc(inline)]
pub use de::{Config, QsDeserializer as Deserializer};
pub use error::Error;
#[doc(inline)]
pub use ser::{to_string, to_writer, Serializer};
Expand Down

0 comments on commit 8283aaf

Please sign in to comment.