diff --git a/src/value/map.rs b/src/value/map.rs index 2c100c024..fd840caa4 100644 --- a/src/value/map.rs +++ b/src/value/map.rs @@ -62,7 +62,14 @@ impl Map { /// Removes an element by its `key`. pub fn remove(&mut self, key: &Value) -> Option { - self.0.remove(key) + #[cfg(feature = "indexmap")] + { + self.0.shift_remove(key) + } + #[cfg(not(feature = "indexmap"))] + { + self.0.remove(key) + } } /// Iterate all key-value pairs. diff --git a/tests/526_flatten.rs b/tests/526_flatten.rs new file mode 100644 index 000000000..7bc56168b --- /dev/null +++ b/tests/526_flatten.rs @@ -0,0 +1,54 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] +struct SomeCollection { + inner: Vec, +} + +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] +struct SomeItem { + #[serde(flatten)] + foo: Foo, + #[serde(flatten)] + bar: Bar, +} + +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] +struct Bar { + name: String, + some_enum: Option, +} + +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] +struct Foo { + something: String, +} + +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] +enum SomeEnum { + A, + B, +} + +#[test] +fn roundtrip() { + let scene = SomeCollection { + inner: vec![SomeItem { + foo: Foo { + something: "something".to_string(), + }, + bar: Bar { + name: "name".to_string(), + some_enum: Some(SomeEnum::A), + }, + }], + }; + + let ron = ron::ser::to_string(&scene).unwrap(); + let de: SomeCollection = ron::de::from_str(&ron).unwrap(); + assert_eq!(de, scene); + + let ron = ron::ser::to_string_pretty(&scene, Default::default()).unwrap(); + let _deser_scene: SomeCollection = ron::de::from_str(&ron).unwrap(); + assert_eq!(de, scene); +}