68: Allow serialization of unit type r=nox a=maxv-rust

That changes provides support for unit type serialization.

It may looks like it doesn't make sense to serialize `()`. Unfortunately that kind of serialization may be necessary for generic structures where one of generic argument may be `()`.

Closes #69 

Co-authored-by: MaxV <60802079+maxv-rust@users.noreply.github.com>
This commit is contained in:
bors[bot] 2020-04-16 10:20:06 +00:00 committed by GitHub
commit ab6f3ce278
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View File

@ -230,9 +230,9 @@ where
Err(Error::top_level())
}
/// Returns an error.
/// Returns `Ok`.
fn serialize_unit(self) -> Result<Self::Ok, Error> {
Err(Error::top_level())
Ok(self.urlencoder)
}
/// Returns `Ok`.

View File

@ -83,3 +83,8 @@ fn deserialize_unit_enum() {
Ok(result)
);
}
#[test]
fn deserialize_unit_type() {
assert_eq!(serde_urlencoded::from_str(""), Ok(()));
}

View File

@ -81,3 +81,8 @@ struct Unit;
fn serialize_unit_struct() {
assert_eq!(serde_urlencoded::to_string(Unit), Ok("".to_owned()));
}
#[test]
fn serialize_unit_type() {
assert_eq!(serde_urlencoded::to_string(()), Ok("".to_owned()));
}