Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose deserialize convenience methods #257

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/decode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ron::de::from_str;
use ron::from_str;
use serde::Deserialize;
use std::collections::HashMap;

Expand Down
2 changes: 1 addition & 1 deletion examples/decode_file.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ron::de::from_reader;
use ron::from_reader;
use serde::Deserialize;
use std::{collections::HashMap, fs::File};

Expand Down
2 changes: 1 addition & 1 deletion examples/encode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ron::ser::{to_string_pretty, PrettyConfig};
use ron::{to_string_pretty, PrettyConfig};
use serde::Serialize;
use std::{collections::HashMap, iter::FromIterator};

Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ Serializing / Deserializing is as simple as calling `to_string` / `from_str`.

#![doc(html_root_url = "https://docs.rs/ron/0.6.0")]

pub mod de;
pub mod ser;
mod de;
mod ser;

pub mod error;
pub mod value;

pub mod extensions;

pub use de::{from_str, Deserializer};
pub use de::{from_bytes, from_reader, from_str, Deserializer};
mainrs marked this conversation as resolved.
Show resolved Hide resolved
pub use error::{Error, Result};
pub use ser::{to_string, Serializer};
pub use ser::{to_string, to_string_pretty, to_writer, to_writer_pretty, PrettyConfig, Serializer};
pub use value::{Map, Number, Value};

mod parse;
2 changes: 1 addition & 1 deletion src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct Pretty {
/// # Examples
///
/// ```
/// use ron::ser::PrettyConfig;
/// use ron::PrettyConfig;
///
/// let my_config = PrettyConfig::new()
/// .depth_limit(4)
Expand Down
2 changes: 1 addition & 1 deletion tests/117_untagged_tuple_variant.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;

use ron::{de::from_str, ser::to_string};
use ron::{from_str, to_string};
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
Expand Down
2 changes: 1 addition & 1 deletion tests/123_enum_representation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ron::{de::from_str, ser::to_string};
use ron::{from_str, to_string};
use serde::{Deserialize, Serialize};
use std::{cmp::PartialEq, fmt::Debug};

Expand Down
6 changes: 3 additions & 3 deletions tests/147_empty_sets_serialisation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ fn empty_sets_arrays() {
.collect(),
};

let pretty = ron::ser::PrettyConfig::new()
let pretty = ron::PrettyConfig::new()
.enumerate_arrays(true)
.new_line("\n".to_string());
let serial = ron::ser::to_string_pretty(&value, pretty).unwrap();
let serial = ron::to_string_pretty(&value, pretty).unwrap();

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

Expand All @@ -63,7 +63,7 @@ fn empty_sets_arrays() {
serial
);

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

assert_eq!(Ok(value), deserial);
}
2 changes: 1 addition & 1 deletion tests/240_array_pretty.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ron::ser::{to_string_pretty, PrettyConfig};
use ron::{to_string_pretty, PrettyConfig};

#[test]
fn small_array() {
Expand Down
2 changes: 1 addition & 1 deletion tests/big_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ const CONFIG: &str = "(

#[test]
fn deserialize_big_struct() {
ron::de::from_str::<ImGuiStyleSave>(CONFIG).unwrap();
ron::from_str::<ImGuiStyleSave>(CONFIG).unwrap();
}
2 changes: 1 addition & 1 deletion tests/borrowed_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const BORROWED: &str = "Borrowed(value: \"test\")";
#[test]
fn borrowed_str() {
assert_eq!(
ron::de::from_str(BORROWED).ok(),
ron::from_str(BORROWED).ok(),
Some(Borrowed { value: "test" })
);
}
2 changes: 1 addition & 1 deletion tests/comments.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ron::de::{from_str, Error as RonErr, ErrorCode, Position};
use ron::{from_str, Error as RonErr, ErrorCode, Position};

#[test]
fn test_simple() {
Expand Down
4 changes: 2 additions & 2 deletions tests/depth_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ fn depth_limit() {
array: vec![(); 3],
};

let pretty = ron::ser::PrettyConfig::new()
let pretty = ron::PrettyConfig::new()
.depth_limit(1)
.separate_tuple_members(true)
.enumerate_arrays(true)
.new_line("\n".to_string());
let s = ron::ser::to_string_pretty(&data, pretty);
let s = ron::to_string_pretty(&data, pretty);

assert_eq!(s, Ok(EXPECTED.to_string()));
}
2 changes: 1 addition & 1 deletion tests/escape.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ron::{de::from_str, ser::to_string};
use ron::{from_str, to_string};
use serde::{Deserialize, Serialize};
use std::{char::from_u32, fmt::Debug};

Expand Down
4 changes: 2 additions & 2 deletions tests/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const CONFIG_U_NT: &str = "

#[test]
fn unwrap_newtypes() {
let d: Struct = ron::de::from_str(&CONFIG_U_NT).expect("Failed to deserialize");
let d: Struct = ron::from_str(&CONFIG_U_NT).expect("Failed to deserialize");

println!("unwrap_newtypes: {:#?}", d);
}
Expand Down Expand Up @@ -75,7 +75,7 @@ const CONFIG_I_S: &str = "

#[test]
fn implicit_some() {
let d: Struct = ron::de::from_str(&CONFIG_I_S).expect("Failed to deserialize");
let d: Struct = ron::from_str(&CONFIG_I_S).expect("Failed to deserialize");

println!("implicit_some: {:#?}", d);
}
5 changes: 1 addition & 4 deletions tests/floats.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use ron::{
de::from_str,
ser::{to_string_pretty, PrettyConfig},
};
use ron::{from_str, to_string_pretty, PrettyConfig};

#[test]
fn test_inf_and_nan() {
Expand Down
8 changes: 4 additions & 4 deletions tests/large_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use ron::value::{Number, Value};
#[test]
fn test_large_number() {
let test_var = Value::Number(Number::new(10000000000000000000000.0f64));
let test_ser = ron::ser::to_string(&test_var).unwrap();
let test_deser = ron::de::from_str::<Value>(&test_ser);
let test_ser = ron::to_string(&test_var).unwrap();
let test_deser = ron::from_str::<Value>(&test_ser);

assert_eq!(
test_deser.unwrap(),
Expand All @@ -17,9 +17,9 @@ fn test_large_integer_to_float() {
use ron::value::Float;
let test_var = std::i64::MAX as u64 + 1;
let expected = test_var as f64; // Is exactly representable by f64
let test_ser = ron::ser::to_string(&test_var).unwrap();
let test_ser = ron::to_string(&test_var).unwrap();
assert_eq!(test_ser, test_var.to_string());
let test_deser = ron::de::from_str::<Value>(&test_ser);
let test_deser = ron::from_str::<Value>(&test_ser);

assert_eq!(
test_deser.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion tests/min_max.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ron::{de::*, ser::*};
use ron::*;

#[test]
fn test_i32_min() {
Expand Down
2 changes: 1 addition & 1 deletion tests/numbers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ron::de::from_str;
use ron::from_str;

#[test]
fn test_hex() {
Expand Down
5 changes: 1 addition & 4 deletions tests/preserve_sequence.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use ron::{
de::from_str,
ser::{to_string_pretty, PrettyConfig},
};
use ron::{from_str, to_string_pretty, PrettyConfig};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

Expand Down
16 changes: 8 additions & 8 deletions tests/roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ fn roundtrip() {
.collect(),
};

let serial = ron::ser::to_string(&value).unwrap();
let serial = ron::to_string(&value).unwrap();

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

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

assert_eq!(Ok(value), deserial);
}
Expand All @@ -68,14 +68,14 @@ fn roundtrip_pretty() {
.collect(),
};

let pretty = ron::ser::PrettyConfig::new()
let pretty = ron::PrettyConfig::new()
.enumerate_arrays(true)
.extensions(Extensions::IMPLICIT_SOME);
let serial = ron::ser::to_string_pretty(&value, pretty).unwrap();
let serial = ron::to_string_pretty(&value, pretty).unwrap();

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

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

assert_eq!(Ok(value), deserial);
}
Expand Down Expand Up @@ -110,12 +110,12 @@ fn roundtrip_sep_tuple_members() {

let value = Both { a, b };

let pretty = ron::ser::PrettyConfig::new().separate_tuple_members(true);
let serial = ron::ser::to_string_pretty(&value, pretty).unwrap();
let pretty = ron::PrettyConfig::new().separate_tuple_members(true);
let serial = ron::to_string_pretty(&value, pretty).unwrap();

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

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

assert_eq!(Ok(value), deserial);
}
4 changes: 2 additions & 2 deletions tests/struct_integers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ fn roundtrip() {
i: std::u64::MAX,
j: std::u128::MAX,
};
let serialized = ron::ser::to_string(&s).unwrap();
let serialized = ron::to_string(&s).unwrap();
dbg!(&serialized);
let deserialized = ron::de::from_str(&serialized).unwrap();
let deserialized = ron::from_str(&serialized).unwrap();
assert_eq!(s, deserialized,);
}
2 changes: 1 addition & 1 deletion tests/unicode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ron::de::from_str;
use ron::from_str;

#[test]
fn test_char() {
Expand Down
2 changes: 1 addition & 1 deletion tests/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct Scene2 {

#[test]
fn roundtrip() {
use ron::{de::from_str, ser::to_string};
use ron::{from_str, to_string};

{
let s = to_string(&Scene2 {
Expand Down