Skip to content

Commit

Permalink
Merge #153
Browse files Browse the repository at this point in the history
153: Format crate and bump to 0.5.0 r=torkleyy a=torkleyy



Co-authored-by: Thomas Schaller <[email protected]>
  • Loading branch information
bors[bot] and torkleyy committed Mar 31, 2019
2 parents 697de99 + 0fd43d4 commit 5a96817
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ron"
version = "0.4.2"
version = "0.5.0"
license = "MIT/Apache-2.0"
keywords = ["parser", "serde", "serialization"]
authors = [
Expand Down
13 changes: 8 additions & 5 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
hard_tabs = false
merge_imports = true
reorder_imports = true
wrap_comments = false
# This was unfortunately removed from rustfmt
# re-enable once it (hopefully) gets added back
# same_line_attributes = false
reorder_impl_items = true
use_field_init_shorthand = true
use_try_shorthand = true
format_doc_comments = true
wrap_comments = true
edition = "2018"
version = "Two"
6 changes: 3 additions & 3 deletions src/de/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// Deserialization module.
///
pub use self::error::{Error, ParseError, Result};
pub use crate::parse::Position;

Expand Down Expand Up @@ -88,8 +87,9 @@ impl<'de> Deserializer<'de> {
}
}

/// Called from `deserialze_any` when a struct was detected. Decides if there is a
/// unit, tuple or usual struct and deserializes it accordingly.
/// Called from `deserialze_any` when a struct was detected. Decides if
/// there is a unit, tuple or usual struct and deserializes it
/// accordingly.
///
/// This method assumes there is no identifier left.
fn handle_any_struct<V>(&mut self, visitor: V) -> Result<V::Value>
Expand Down
23 changes: 11 additions & 12 deletions src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,15 @@ impl Serializer {
}

impl<'a> ser::Serializer for &'a mut Serializer {
type Ok = ();
type Error = Error;

type Ok = ();
type SerializeMap = Self;
type SerializeSeq = Self;
type SerializeStruct = Self;
type SerializeStructVariant = Self;
type SerializeTuple = Self;
type SerializeTupleStruct = Self;
type SerializeTupleVariant = Self;
type SerializeMap = Self;
type SerializeStruct = Self;
type SerializeStructVariant = Self;

fn serialize_bool(self, v: bool) -> Result<()> {
self.output += if v { "true" } else { "false" };
Expand Down Expand Up @@ -464,8 +463,8 @@ impl<'a> ser::Serializer for &'a mut Serializer {
}

impl<'a> ser::SerializeSeq for &'a mut Serializer {
type Ok = ();
type Error = Error;
type Ok = ();

fn serialize_element<T>(&mut self, value: &T) -> Result<()>
where
Expand Down Expand Up @@ -506,8 +505,8 @@ impl<'a> ser::SerializeSeq for &'a mut Serializer {
}

impl<'a> ser::SerializeTuple for &'a mut Serializer {
type Ok = ();
type Error = Error;
type Ok = ();

fn serialize_element<T>(&mut self, value: &T) -> Result<()>
where
Expand Down Expand Up @@ -549,8 +548,8 @@ impl<'a> ser::SerializeTuple for &'a mut Serializer {

// Same thing but for tuple structs.
impl<'a> ser::SerializeTupleStruct for &'a mut Serializer {
type Ok = ();
type Error = Error;
type Ok = ();

fn serialize_field<T>(&mut self, value: &T) -> Result<()>
where
Expand All @@ -565,8 +564,8 @@ impl<'a> ser::SerializeTupleStruct for &'a mut Serializer {
}

impl<'a> ser::SerializeTupleVariant for &'a mut Serializer {
type Ok = ();
type Error = Error;
type Ok = ();

fn serialize_field<T>(&mut self, value: &T) -> Result<()>
where
Expand All @@ -581,8 +580,8 @@ impl<'a> ser::SerializeTupleVariant for &'a mut Serializer {
}

impl<'a> ser::SerializeMap for &'a mut Serializer {
type Ok = ();
type Error = Error;
type Ok = ();

fn serialize_key<T>(&mut self, key: &T) -> Result<()>
where
Expand Down Expand Up @@ -624,8 +623,8 @@ impl<'a> ser::SerializeMap for &'a mut Serializer {
}

impl<'a> ser::SerializeStruct for &'a mut Serializer {
type Ok = ();
type Error = Error;
type Ok = ();

fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<()>
where
Expand Down Expand Up @@ -661,8 +660,8 @@ impl<'a> ser::SerializeStruct for &'a mut Serializer {
}

impl<'a> ser::SerializeStructVariant for &'a mut Serializer {
type Ok = ();
type Error = Error;
type Ok = ();

fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<()>
where
Expand Down
12 changes: 6 additions & 6 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ impl Value {
impl<'de> Deserializer<'de> for Value {
type Error = RonError;

forward_to_deserialize_any! {
bool f32 f64 char str string bytes
byte_buf option unit unit_struct newtype_struct seq tuple
tuple_struct map struct enum identifier ignored_any
}

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
where
V: Visitor<'de>,
Expand Down Expand Up @@ -161,12 +167,6 @@ impl<'de> Deserializer<'de> for Value {
v => Err(RonError::custom(format!("Expected a number, got {:?}", v))),
}
}

forward_to_deserialize_any! {
bool f32 f64 char str string bytes
byte_buf option unit unit_struct newtype_struct seq tuple
tuple_struct map struct enum identifier ignored_any
}
}

struct Map {
Expand Down
23 changes: 10 additions & 13 deletions tests/147_empty_sets_serialisation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,11 @@ fn empty_sets_arrays() {
let value = Struct {
tuple: ((), NewType(0.5), TupleStruct(UnitStruct, -5)),
vec: vec![],
map: vec![]
.into_iter()
.collect(),
deep_vec: vec![
(Key(0), vec![]),
]
.into_iter()
.collect(),
deep_map: vec![
(Key(0), vec![].into_iter().collect(),),
].into_iter().collect(),
map: vec![].into_iter().collect(),
deep_vec: vec![(Key(0), vec![])].into_iter().collect(),
deep_map: vec![(Key(0), vec![].into_iter().collect())]
.into_iter()
.collect(),
};

let pretty = ron::ser::PrettyConfig {
Expand All @@ -55,7 +49,8 @@ fn empty_sets_arrays() {

println!("Serialized: {}", serial);

assert_eq!("(
assert_eq!(
"(
tuple: ((), (0.5), ((), -5)),
vec: [],
map: {},
Expand All @@ -65,7 +60,9 @@ fn empty_sets_arrays() {
deep_map: {
(0): {},
},
)", serial);
)",
serial
);

let deserial = ron::de::from_str(&serial);

Expand Down

0 comments on commit 5a96817

Please sign in to comment.