Skip to content

Commit 6825f0c

Browse files
authored
Merge pull request #324 from ron-rs/esc_ident
Backport (#323): Serialize struct idents with Serializer::write_identifier
2 parents 4993b34 + eab3bfa commit 6825f0c

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.6.6] - 2020-10-21
8+
9+
- Fix serialization of raw identifiers ([#323](https://github.com/ron-rs/ron/pull/323))
10+
- Add `unwrap_variant_newtypes` extension ([#319](https://github.com/ron-rs/ron/pull/319))
11+
712
## [0.6.5] - 2021-09-09
813
- support serde renames that start with a digit
914

1015
## [0.6.3] - 2020-12-18
1116
- bump `base64` dependency to 0.13
1217

1318
## [0.6.2] - 2020-09-09
19+
1420
- Added `decimal_floats` PrettyConfig option, which always includes decimals in floats (`1.0` vs `1`) ([#237](https://github.com/ron-rs/ron/pull/237))
1521
- Fixed EBNF grammar for raw strings ([#236](https://github.com/ron-rs/ron/pull/236), unsigned integers ([#248](https://github.com/ron-rs/ron/pull/248)), and nested comments ([#272](https://github.com/ron-rs/ron/pull/272))
1622
- Added `ser::to_writer_pretty` ([#269](https://github.com/ron-rs/ron/pull/269))

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "ron"
33
# Memo: update version in src/lib.rs too (doc link)
4-
version = "0.6.5"
4+
version = "0.6.6"
55
license = "MIT/Apache-2.0"
66
keywords = ["parser", "serde", "serialization"]
77
authors = [

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Serializing / Deserializing is as simple as calling `to_string` / `from_str`.
5757
5858
!*/
5959

60-
#![doc(html_root_url = "https://docs.rs/ron/0.6.5")]
60+
#![doc(html_root_url = "https://docs.rs/ron/0.6.6")]
6161

6262
pub mod de;
6363
pub mod ser;

src/ser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ impl<'a, W: io::Write> ser::SerializeStruct for Compound<'a, W> {
928928
}
929929
};
930930
ser.indent()?;
931-
ser.output.write_all(key.as_bytes())?;
931+
ser.write_identifier(key)?;
932932
ser.output.write_all(b":")?;
933933

934934
if ser.is_pretty() {

tests/322_escape_idents.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use serde::{Deserialize, Serialize};
2+
use std::collections::HashMap;
3+
4+
#[derive(Debug, Deserialize, PartialEq, Serialize)]
5+
#[serde(rename_all = "kebab-case")]
6+
enum MyEnumWithDashes {
7+
ThisIsMyUnitVariant,
8+
ThisIsMyTupleVariant(bool, i32),
9+
}
10+
11+
#[derive(Debug, Deserialize, PartialEq, Serialize)]
12+
#[serde(rename_all = "kebab-case")]
13+
struct MyStructWithDashes {
14+
my_enum: MyEnumWithDashes,
15+
#[serde(rename = "2nd")]
16+
my_enum2: MyEnumWithDashes,
17+
will_be_renamed: u32,
18+
}
19+
20+
#[test]
21+
fn roundtrip_ident_with_dash() {
22+
let value = MyStructWithDashes {
23+
my_enum: MyEnumWithDashes::ThisIsMyUnitVariant,
24+
my_enum2: MyEnumWithDashes::ThisIsMyTupleVariant(false, -3),
25+
will_be_renamed: 32,
26+
};
27+
28+
let serial = ron::ser::to_string(&value).unwrap();
29+
30+
println!("Serialized: {}", serial);
31+
32+
let deserial = ron::de::from_str(&serial);
33+
34+
assert_eq!(Ok(value), deserial);
35+
}

0 commit comments

Comments
 (0)