Lines
100 %
Functions
42.55 %
Branches
use std::collections::HashMap;
use ron::extensions::Extensions;
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Deserialize, Serialize)]
struct UnitStruct;
struct NewType(f32);
struct TupleStruct(UnitStruct, i8);
#[derive(Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
struct Key(u32);
enum Enum {
Unit,
Bool(bool),
Chars(char, String),
}
struct Struct {
tuple: ((), NewType, TupleStruct),
vec: Vec<Option<UnitStruct>>,
map: HashMap<Key, Enum>,
#[test]
fn roundtrip() {
let value = Struct {
tuple: ((), NewType(0.5), TupleStruct(UnitStruct, -5)),
vec: vec![None, Some(UnitStruct)],
map: vec![
(Key(5), Enum::Unit),
(Key(6), Enum::Bool(false)),
(Key(7), Enum::Bool(true)),
(Key(9), Enum::Chars('x', "".to_string())),
]
.into_iter()
.collect(),
};
let serial = ron::ser::to_string(&value).unwrap();
println!("Serialized: {}", serial);
let deserial = ron::de::from_str(&serial);
assert_eq!(Ok(value), deserial);
fn roundtrip_pretty() {
let pretty = ron::ser::PrettyConfig::new()
.enumerate_arrays(true)
.extensions(Extensions::IMPLICIT_SOME);
let serial = ron::ser::to_string_pretty(&value, pretty).unwrap();
fn roundtrip_sep_tuple_members() {
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize)]
pub enum FileOrMem {
File(String),
Memory,
#[derive(Debug, Deserialize, PartialEq, Serialize)]
struct Both {
a: Struct,
b: FileOrMem,
let a = Struct {
let b = FileOrMem::File("foo".to_owned());
let value = Both { a, b };
let pretty = ron::ser::PrettyConfig::new().separate_tuple_members(true);