From 31b5e882aa9058bf19534ab40ee6efa1ce6b2d73 Mon Sep 17 00:00:00 2001 From: Sam Scott Date: Fri, 10 Mar 2017 13:27:42 -0500 Subject: Cleaning up, modifying docs. --- src/lib.rs | 18 +++++++++++++++--- src/ser/key.rs | 6 +++--- src/ser/mod.rs | 7 +++---- src/ser/part.rs | 2 +- src/ser/value.rs | 2 +- 5 files changed, 23 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index a1ce6c3..f28d916 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,20 @@ //! Serde support for querystring-style strings +//! +//! Querystrings are not formally defined and loosely take the form of +//! _nested_ urlencoded queries. +//! +//! This library aims for compatability with the syntax of +//! [qs](https://github.com/ljharb/qs) and also of the [Rack::Utils::parse_neste +//! d_query](http://www.rubydoc.info/github/rack/rack/Rack/Utils +//! #parse_nested_query-class_method) implementation. +//! +//! For users who do *not* require nested URL parameters, it is highly +//! recommended that the `serde_urlencoded` crate is used instead, which +//! will almost certainly perform better for deserializing simple inputs. +//! +//! The serialization implementation of this library is adapted from +//! `serde_urlencoded`. -#![warn(unused_extern_crates)] - -extern crate fnv; extern crate itoa; extern crate dtoa; #[macro_use] diff --git a/src/ser/key.rs b/src/ser/key.rs index eb7ffae..5b2ccdd 100644 --- a/src/ser/key.rs +++ b/src/ser/key.rs @@ -70,7 +70,7 @@ impl Sink for KeySink Err(self.unsupported()) } - fn unsupported(self) -> Error { + fn unsupported(&self) -> Error { Error::Custom("unsupported key".into()) } } @@ -85,7 +85,7 @@ where End: for<'key> FnOnce(Key<'key>) -> Result _key: &'static str, _value: &T) -> Result<(), Error> { - Err(Error::top_level()) + Err(self.unsupported()) } fn end(self) -> Result { @@ -102,7 +102,7 @@ where End: for<'key> FnOnce(Key<'key>) -> Result fn serialize_element(&mut self, _value: &T) -> Result<(), Error> { - Err(Error::top_level()) + Err(self.unsupported()) } fn end(self) -> Result { diff --git a/src/ser/mod.rs b/src/ser/mod.rs index 596730e..f732bb3 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -46,11 +46,10 @@ pub fn to_string(input: &T) -> Result { /// A serializer for the querystring format. /// -/// * Supported top-level inputs are structs, maps and sequences of pairs, -/// with or without a given length. +/// * Supported top-level inputs are structs and maps. /// -/// * Supported keys and values are integers, bytes (if convertible to strings), -/// unit structs and unit variants. +/// * Supported values are currently most primitive types, structs, maps and +/// sequences. Sequences are serialized with an incrementing key index. /// /// * Newtype structs defer to their inner values. pub struct Serializer<'output, Target: 'output + UrlEncodedTarget> { diff --git a/src/ser/part.rs b/src/ser/part.rs index d456f4b..4cf90b3 100644 --- a/src/ser/part.rs +++ b/src/ser/part.rs @@ -35,7 +35,7 @@ pub trait Sink: Sized + ser::SerializeStruct + ser::Seriali value: &T) -> Result; - fn unsupported(self) -> Error; + fn unsupported(&self) -> Error; } impl> ser::Serializer for PartSerializer { diff --git a/src/ser/value.rs b/src/ser/value.rs index 832cbf3..5ed80b9 100644 --- a/src/ser/value.rs +++ b/src/ser/value.rs @@ -55,7 +55,7 @@ impl<'key, 'target, Target> Sink<(), Error> for ValueSink<'key, 'target, Target> value.serialize(PartSerializer::new(self)) } - fn unsupported(self) -> Error { + fn unsupported(&self) -> Error { Error::Custom("unsupported value".into()) } } -- cgit v1.2.3