feat: allow serialization of unit structs

This commit is contained in:
Florian Dehau 2019-01-13 23:17:45 +01:00
parent 643a206559
commit 76b45ee001
2 changed files with 10 additions and 2 deletions

View File

@ -227,12 +227,12 @@ where
Err(Error::top_level()) Err(Error::top_level())
} }
/// Returns an error. /// Returns `Ok`.
fn serialize_unit_struct( fn serialize_unit_struct(
self, self,
_name: &'static str, _name: &'static str,
) -> Result<Self::Ok, Error> { ) -> Result<Self::Ok, Error> {
Err(Error::top_level()) Ok(self.urlencoder)
} }
/// Returns an error. /// Returns an error.

View File

@ -73,3 +73,11 @@ fn serialize_unit_enum() {
Ok("one=A&two=B&three=C".to_owned()) Ok("one=A&two=B&three=C".to_owned())
); );
} }
#[derive(Serialize)]
struct Unit;
#[test]
fn serialize_unit_struct() {
assert_eq!(serde_urlencoded::to_string(Unit), Ok("".to_owned()));
}