Releases: serde-rs/serde
v0.9.12
-
Add
#[serde(into = "T")]
to serialize using the implementation ofInto<T>
and#[serde(from = "T")]
to deserialize using the implementation ofFrom<T>
(#817, thanks @jbaublitz)#[derive(Serialize, Deserialize)] #[serde(into = "u32", from = "u32")] struct Ipv4Addr { /* ... */ }
-
Implement Deserialize for
Box<CStr>
on nightly (#811, thanks @jonhoo) -
Implement Serialize and Deserialize for
OsString
and implement Serialize forOsStr
(#824, thanks @alexcrichton) -
Implement Serialize for
Range
(#813, thanks @rocallahan)
v0.9.11
v0.9.10
-
Add a
rename_all
attribute to rename all the fields of a struct or struct variant, or all the variants of an enum.#[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] struct S { first_field: u8, // gets renamed to firstField second_field: u8, // gets renamed to secondField }
The possible renames are:
#[serde(rename_all = "PascalCase")]
#[serde(rename_all = "camelCase")]
#[serde(rename_all = "snake_case")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "kebab-case")]
v0.9.9
v0.9.8
-
Add
with = "..."
attribute that serves as a combination of serialize_with and deserialize_with (#763)#[derive(Serialize, Deserialize)] struct MyStruct { - #[serde(serialize_with = "hyper_serde::serialize", - deserialize_with = "hyper_serde::deserialize")] + #[serde(with = "hyper_serde")] headers: Headers, }
Whatever path you give, Serde will use
$path::serialize
as the serializer and$path::deserialize
as the deserializer. -
Haskell / Pandoc style adjacently tagged enums (#758, thanks @elliottslaughter)
#[derive(Serialize, Deserialize)] #[serde(tag = "t", content = "c")] enum MyType { One(String), Two(u8, u8), }
Written in JSON syntax, this enum would be represented as:
{ "t": "One", "c": "whatever string" } { "t": "Two", "c": [127, 1] }
-
Allow
serde(default)
attribute on structs (#780, thanks @Thomasdezeeuw)#[derive(Serialize, Deserialize)] #[serde(default)] struct StructDefault { a: i32, b: String, } impl Default for StructDefault { fn default() -> Self { StructDefault { a: 100, b: "default".to_string(), } } }
-
Clamp size hints coming from untrusted input to 4096 (#774, thanks @nox)
This mitigates some types of attacks where untrusted input can instigate the allocation of large vectors or maps.
-
Optimize the serialization of various std::net types (#778, thanks @SimonSapin)
v0.9.7
-
Add
Serializer::collect_seq
andSerializer::collect_map
to simplify some Serialize impls (#736)- let mut map = serializer.serialize_map(Some(self.len()))?; - for (k, v) in self { - map.serialize_key(k)?; - map.serialize_value(v)?; - } - map.end() + serializer.collect_map(self)
v0.9.6
- Support for untagged and internally tagged enum representations; see the manual for details (#739)
- Remove Serialize and Deserialize impls for collections::enum_set::EnumSet which has been deprecated for a long time (#740)
- Fix compilation errors in generated code when Ok or Err were redefined from their usual meaning within the same module (#737)