rustfmt librbml

This commit is contained in:
Nick Cameron 2016-01-19 14:30:48 +13:00
parent 08886499cf
commit 7c2bfd12a0
3 changed files with 506 additions and 464 deletions

View File

@ -9,8 +9,7 @@
// except according to those terms.
#[inline]
pub fn write_to_vec(vec: &mut Vec<u8>, position: &mut usize, byte: u8)
{
pub fn write_to_vec(vec: &mut Vec<u8>, position: &mut usize, byte: u8) {
if *position == vec.len() {
vec.push(byte);
} else {
@ -20,13 +19,9 @@ pub fn write_to_vec(vec: &mut Vec<u8>, position: &mut usize, byte: u8)
*position += 1;
}
pub fn write_unsigned_leb128(out: &mut Vec<u8>,
start_position: usize,
mut value: u64)
-> usize {
pub fn write_unsigned_leb128(out: &mut Vec<u8>, start_position: usize, mut value: u64) -> usize {
let mut position = start_position;
loop
{
loop {
let mut byte = (value & 0x7F) as u8;
value >>= 7;
if value != 0 {
@ -43,9 +38,7 @@ pub fn write_unsigned_leb128(out: &mut Vec<u8>,
return position - start_position;
}
pub fn read_unsigned_leb128(data: &[u8],
start_position: usize)
-> (u64, usize) {
pub fn read_unsigned_leb128(data: &[u8], start_position: usize) -> (u64, usize) {
let mut result = 0;
let mut shift = 0;
let mut position = start_position;
@ -63,15 +56,13 @@ pub fn read_unsigned_leb128(data: &[u8],
}
pub fn write_signed_leb128(out: &mut Vec<u8>,
start_position: usize,
mut value: i64) -> usize {
pub fn write_signed_leb128(out: &mut Vec<u8>, start_position: usize, mut value: i64) -> usize {
let mut position = start_position;
loop {
let mut byte = (value as u8) & 0x7f;
value >>= 7;
let more = !((((value == 0 ) && ((byte & 0x40) == 0)) ||
let more = !((((value == 0) && ((byte & 0x40) == 0)) ||
((value == -1) && ((byte & 0x40) != 0))));
if more {
byte |= 0x80; // Mark this byte to show that more bytes will follow.
@ -87,9 +78,7 @@ pub fn write_signed_leb128(out: &mut Vec<u8>,
return position - start_position;
}
pub fn read_signed_leb128(data: &[u8],
start_position: usize)
-> (i64, usize) {
pub fn read_signed_leb128(data: &[u8], start_position: usize) -> (i64, usize) {
let mut result = 0;
let mut shift = 0;
let mut position = start_position;
@ -107,7 +96,7 @@ pub fn read_signed_leb128(data: &[u8],
}
if (shift < 64) && ((byte & 0x40) != 0) {
/* sign extend */
// sign extend
result |= -(1i64 << shift);
}

File diff suppressed because it is too large Load Diff

View File

@ -10,14 +10,13 @@
use Error as DecodeError;
use writer::EncodeResult;
use leb128::{read_signed_leb128, read_unsigned_leb128, write_signed_leb128,
write_unsigned_leb128};
use leb128::{read_signed_leb128, read_unsigned_leb128, write_signed_leb128, write_unsigned_leb128};
use std::io::{self, Write};
use serialize;
//=-----------------------------------------------------------------------------
// =-----------------------------------------------------------------------------
// Encoder
//=-----------------------------------------------------------------------------
// =-----------------------------------------------------------------------------
pub struct Encoder<'a> {
pub cursor: &'a mut io::Cursor<Vec<u8>>,
@ -25,9 +24,7 @@ pub struct Encoder<'a> {
impl<'a> Encoder<'a> {
pub fn new(cursor: &'a mut io::Cursor<Vec<u8>>) -> Encoder<'a> {
Encoder {
cursor: cursor
}
Encoder { cursor: cursor }
}
}
@ -101,7 +98,11 @@ impl<'a> serialize::Encoder for Encoder<'a> {
}
fn emit_bool(&mut self, v: bool) -> EncodeResult {
self.emit_u8(if v { 1 } else { 0 })
self.emit_u8(if v {
1
} else {
0
})
}
fn emit_f64(&mut self, v: f64) -> EncodeResult {
@ -125,7 +126,8 @@ impl<'a> serialize::Encoder for Encoder<'a> {
}
fn emit_enum<F>(&mut self, _name: &str, f: F) -> EncodeResult
where F: FnOnce(&mut Self) -> EncodeResult {
where F: FnOnce(&mut Self) -> EncodeResult
{
f(self)
}
@ -133,76 +135,75 @@ impl<'a> serialize::Encoder for Encoder<'a> {
_v_name: &str,
v_id: usize,
_len: usize,
f: F) -> EncodeResult
f: F)
-> EncodeResult
where F: FnOnce(&mut Self) -> EncodeResult
{
try!(self.emit_uint(v_id));
f(self)
}
fn emit_enum_variant_arg<F>(&mut self, _: usize, f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
fn emit_enum_variant_arg<F>(&mut self, _: usize, f: F) -> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
f(self)
}
fn emit_enum_struct_variant<F>(&mut self,
v_name: &str,
v_id: usize,
cnt: usize,
f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
v_name: &str,
v_id: usize,
cnt: usize,
f: F)
-> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
self.emit_enum_variant(v_name, v_id, cnt, f)
}
fn emit_enum_struct_variant_field<F>(&mut self,
_: &str,
idx: usize,
f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
fn emit_enum_struct_variant_field<F>(&mut self, _: &str, idx: usize, f: F) -> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
self.emit_enum_variant_arg(idx, f)
}
fn emit_struct<F>(&mut self, _: &str, _len: usize, f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
fn emit_struct<F>(&mut self, _: &str, _len: usize, f: F) -> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
f(self)
}
fn emit_struct_field<F>(&mut self, _name: &str, _: usize, f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
fn emit_struct_field<F>(&mut self, _name: &str, _: usize, f: F) -> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
f(self)
}
fn emit_tuple<F>(&mut self, len: usize, f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
fn emit_tuple<F>(&mut self, len: usize, f: F) -> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
self.emit_seq(len, f)
}
fn emit_tuple_arg<F>(&mut self, idx: usize, f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
fn emit_tuple_arg<F>(&mut self, idx: usize, f: F) -> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
self.emit_seq_elt(idx, f)
}
fn emit_tuple_struct<F>(&mut self, _: &str, len: usize, f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
fn emit_tuple_struct<F>(&mut self, _: &str, len: usize, f: F) -> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
self.emit_seq(len, f)
}
fn emit_tuple_struct_arg<F>(&mut self, idx: usize, f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
fn emit_tuple_struct_arg<F>(&mut self, idx: usize, f: F) -> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
self.emit_seq_elt(idx, f)
}
fn emit_option<F>(&mut self, f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
fn emit_option<F>(&mut self, f: F) -> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
self.emit_enum("Option", f)
}
@ -211,40 +212,40 @@ impl<'a> serialize::Encoder for Encoder<'a> {
self.emit_enum_variant("None", 0, 0, |_| Ok(()))
}
fn emit_option_some<F>(&mut self, f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
fn emit_option_some<F>(&mut self, f: F) -> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
self.emit_enum_variant("Some", 1, 1, f)
}
fn emit_seq<F>(&mut self, len: usize, f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
fn emit_seq<F>(&mut self, len: usize, f: F) -> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
try!(self.emit_uint(len));
f(self)
}
fn emit_seq_elt<F>(&mut self, _idx: usize, f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
fn emit_seq_elt<F>(&mut self, _idx: usize, f: F) -> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
f(self)
}
fn emit_map<F>(&mut self, len: usize, f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
fn emit_map<F>(&mut self, len: usize, f: F) -> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
try!(self.emit_uint(len));
f(self)
}
fn emit_map_elt_key<F>(&mut self, _idx: usize, f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
fn emit_map_elt_key<F>(&mut self, _idx: usize, f: F) -> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
f(self)
}
fn emit_map_elt_val<F>(&mut self, _idx: usize, f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
fn emit_map_elt_val<F>(&mut self, _idx: usize, f: F) -> EncodeResult
where F: FnOnce(&mut Encoder<'a>) -> EncodeResult
{
f(self)
}
@ -256,15 +257,13 @@ impl<'a> Encoder<'a> {
}
pub fn from_rbml<'b: 'c, 'c>(rbml: &'c mut ::writer::Encoder<'b>) -> Encoder<'c> {
Encoder {
cursor: rbml.writer
}
Encoder { cursor: rbml.writer }
}
}
//=-----------------------------------------------------------------------------
// =-----------------------------------------------------------------------------
// Decoder
//=-----------------------------------------------------------------------------
// =-----------------------------------------------------------------------------
pub struct Decoder<'a> {
pub data: &'a [u8],
@ -275,7 +274,7 @@ impl<'a> Decoder<'a> {
pub fn new(data: &'a [u8], position: usize) -> Decoder<'a> {
Decoder {
data: data,
position: position
position: position,
}
}
@ -349,9 +348,7 @@ impl<'a> serialize::Decoder for Decoder<'a> {
fn read_i8(&mut self) -> Result<i8, Self::Error> {
let as_u8 = self.data[self.position];
self.position += 1;
unsafe {
Ok(::std::mem::transmute(as_u8))
}
unsafe { Ok(::std::mem::transmute(as_u8)) }
}
fn read_int(&mut self) -> Result<isize, Self::Error> {
@ -380,37 +377,32 @@ impl<'a> serialize::Decoder for Decoder<'a> {
fn read_str(&mut self) -> Result<String, Self::Error> {
let len = try!(self.read_uint());
let s = ::std::str::from_utf8(&self.data[self.position .. self.position + len]).unwrap();
let s = ::std::str::from_utf8(&self.data[self.position..self.position + len]).unwrap();
self.position += len;
Ok(s.to_string())
}
fn read_enum<T, F>(&mut self, _name: &str, f: F) -> Result<T, Self::Error> where
F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>,
fn read_enum<T, F>(&mut self, _name: &str, f: F) -> Result<T, Self::Error>
where F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>
{
f(self)
}
fn read_enum_variant<T, F>(&mut self,
_: &[&str],
mut f: F)
-> Result<T, Self::Error>
where F: FnMut(&mut Decoder<'a>, usize) -> Result<T, Self::Error>,
fn read_enum_variant<T, F>(&mut self, _: &[&str], mut f: F) -> Result<T, Self::Error>
where F: FnMut(&mut Decoder<'a>, usize) -> Result<T, Self::Error>
{
let disr = try!(self.read_uint());
f(self, disr)
}
fn read_enum_variant_arg<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Self::Error> where
F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>,
fn read_enum_variant_arg<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Self::Error>
where F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>
{
f(self)
}
fn read_enum_struct_variant<T, F>(&mut self,
_: &[&str],
mut f: F) -> Result<T, Self::Error>
where F: FnMut(&mut Decoder<'a>, usize) -> Result<T, Self::Error>,
fn read_enum_struct_variant<T, F>(&mut self, _: &[&str], mut f: F) -> Result<T, Self::Error>
where F: FnMut(&mut Decoder<'a>, usize) -> Result<T, Self::Error>
{
let disr = try!(self.read_uint());
f(self, disr)
@ -420,68 +412,59 @@ impl<'a> serialize::Decoder for Decoder<'a> {
_name: &str,
_idx: usize,
f: F)
-> Result<T, Self::Error> where
F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>,
-> Result<T, Self::Error>
where F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>
{
f(self)
}
fn read_struct<T, F>(&mut self, _name: &str, _: usize, f: F) -> Result<T, Self::Error> where
F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>,
fn read_struct<T, F>(&mut self, _name: &str, _: usize, f: F) -> Result<T, Self::Error>
where F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>
{
f(self)
}
fn read_struct_field<T, F>(&mut self,
_name: &str,
_idx: usize, f: F)
-> Result<T, Self::Error> where
F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>,
fn read_struct_field<T, F>(&mut self, _name: &str, _idx: usize, f: F) -> Result<T, Self::Error>
where F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>
{
f(self)
}
fn read_tuple<T, F>(&mut self, tuple_len: usize, f: F) -> Result<T, Self::Error> where
F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>,
fn read_tuple<T, F>(&mut self, tuple_len: usize, f: F) -> Result<T, Self::Error>
where F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>
{
self.read_seq(move |d, len| {
if len == tuple_len {
f(d)
} else {
let err = format!("Invalid tuple length. Expected {}, found {}",
tuple_len,
len);
tuple_len,
len);
Err(DecodeError::Expected(err))
}
})
}
fn read_tuple_arg<T, F>(&mut self, idx: usize, f: F) -> Result<T, Self::Error> where
F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>,
fn read_tuple_arg<T, F>(&mut self, idx: usize, f: F) -> Result<T, Self::Error>
where F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>
{
self.read_seq_elt(idx, f)
}
fn read_tuple_struct<T, F>(&mut self,
_name: &str,
len: usize, f: F)
-> Result<T, Self::Error> where
F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>,
fn read_tuple_struct<T, F>(&mut self, _name: &str, len: usize, f: F) -> Result<T, Self::Error>
where F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>
{
self.read_tuple(len, f)
}
fn read_tuple_struct_arg<T, F>(&mut self,
idx: usize,
f: F)
-> Result<T, Self::Error> where
F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>,
fn read_tuple_struct_arg<T, F>(&mut self, idx: usize, f: F) -> Result<T, Self::Error>
where F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>
{
self.read_tuple_arg(idx, f)
}
fn read_option<T, F>(&mut self, mut f: F) -> Result<T, Self::Error> where
F: FnMut(&mut Decoder<'a>, bool) -> Result<T, Self::Error>,
fn read_option<T, F>(&mut self, mut f: F) -> Result<T, Self::Error>
where F: FnMut(&mut Decoder<'a>, bool) -> Result<T, Self::Error>
{
self.read_enum("Option", move |this| {
this.read_enum_variant(&["None", "Some"], move |this, idx| {
@ -497,34 +480,34 @@ impl<'a> serialize::Decoder for Decoder<'a> {
})
}
fn read_seq<T, F>(&mut self, f: F) -> Result<T, Self::Error> where
F: FnOnce(&mut Decoder<'a>, usize) -> Result<T, Self::Error>,
fn read_seq<T, F>(&mut self, f: F) -> Result<T, Self::Error>
where F: FnOnce(&mut Decoder<'a>, usize) -> Result<T, Self::Error>
{
let len = try!(self.read_uint());
f(self, len)
}
fn read_seq_elt<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Self::Error> where
F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>,
fn read_seq_elt<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Self::Error>
where F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>
{
f(self)
}
fn read_map<T, F>(&mut self, f: F) -> Result<T, Self::Error> where
F: FnOnce(&mut Decoder<'a>, usize) -> Result<T, Self::Error>,
fn read_map<T, F>(&mut self, f: F) -> Result<T, Self::Error>
where F: FnOnce(&mut Decoder<'a>, usize) -> Result<T, Self::Error>
{
let len = try!(self.read_uint());
f(self, len)
}
fn read_map_elt_key<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Self::Error> where
F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>,
fn read_map_elt_key<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Self::Error>
where F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>
{
f(self)
}
fn read_map_elt_val<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Self::Error> where
F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>,
fn read_map_elt_val<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Self::Error>
where F: FnOnce(&mut Decoder<'a>) -> Result<T, Self::Error>
{
f(self)
}
@ -538,7 +521,7 @@ impl<'a> serialize::Decoder for Decoder<'a> {
#[cfg(test)]
mod tests {
use serialize::{Encodable, Decodable};
use std::io::{Cursor};
use std::io::Cursor;
use std::fmt::Debug;
use super::{Encoder, Decoder};
@ -566,7 +549,7 @@ mod tests {
}
fn check_round_trip<T: Encodable+Decodable+PartialEq+Debug>(values: Vec<T>) {
fn check_round_trip<T: Encodable + Decodable + PartialEq + Debug>(values: Vec<T>) {
let mut cursor = Cursor::new(Vec::new());
for value in &values {
@ -591,7 +574,7 @@ mod tests {
#[test]
fn test_u8() {
let mut vec = vec![];
for i in ::std::u8::MIN .. ::std::u8::MAX {
for i in ::std::u8::MIN..::std::u8::MAX {
vec.push(i);
}
check_round_trip(vec);
@ -599,7 +582,7 @@ mod tests {
#[test]
fn test_u16() {
for i in ::std::u16::MIN .. ::std::u16::MAX {
for i in ::std::u16::MIN..::std::u16::MAX {
check_round_trip(vec![1, 2, 3, i, i, i]);
}
}
@ -622,7 +605,7 @@ mod tests {
#[test]
fn test_i8() {
let mut vec = vec![];
for i in ::std::i8::MIN .. ::std::i8::MAX {
for i in ::std::i8::MIN..::std::i8::MAX {
vec.push(i);
}
check_round_trip(vec);
@ -630,7 +613,7 @@ mod tests {
#[test]
fn test_i16() {
for i in ::std::i16::MIN .. ::std::i16::MAX {
for i in ::std::i16::MIN..::std::i16::MAX {
check_round_trip(vec![-1, 2, -3, i, i, i, 2]);
}
}
@ -658,8 +641,8 @@ mod tests {
#[test]
fn test_f32() {
let mut vec = vec![];
for i in -100 .. 100 {
vec.push( (i as f32) / 3.0 );
for i in -100..100 {
vec.push((i as f32) / 3.0);
}
check_round_trip(vec);
}
@ -667,8 +650,8 @@ mod tests {
#[test]
fn test_f64() {
let mut vec = vec![];
for i in -100 .. 100 {
vec.push( (i as f64) / 3.0 );
for i in -100..100 {
vec.push((i as f64) / 3.0);
}
check_round_trip(vec);
}
@ -681,14 +664,13 @@ mod tests {
#[test]
fn test_string() {
let vec = vec![
"abcbuÖeiovÄnameÜavmpßvmea€µsbpnvapeapmaebn".to_string(),
"abcbuÖganeiovÄnameÜavmpßvmea€µsbpnvapeapmaebn".to_string(),
"abcbuÖganeiovÄnameÜavmpßvmea€µsbpapmaebn".to_string(),
"abcbuÖganeiovÄnameÜavmpßvmeabpnvapeapmaebn".to_string(),
"abcbuÖganeiÄnameÜavmpßvmea€µsbpnvapeapmaebn".to_string(),
"abcbuÖganeiovÄnameÜavmpßvmea€µsbpmaebn".to_string(),
"abcbuÖganeiovÄnameÜavmpßvmea€µnvapeapmaebn".to_string()];
let vec = vec!["abcbuÖeiovÄnameÜavmpßvmea€µsbpnvapeapmaebn".to_string(),
"abcbuÖganeiovÄnameÜavmpßvmea€µsbpnvapeapmaebn".to_string(),
"abcbuÖganeiovÄnameÜavmpßvmea€µsbpapmaebn".to_string(),
"abcbuÖganeiovÄnameÜavmpßvmeabpnvapeapmaebn".to_string(),
"abcbuÖganeiÄnameÜavmpßvmea€µsbpnvapeapmaebn".to_string(),
"abcbuÖganeiovÄnameÜavmpßvmea€µsbpmaebn".to_string(),
"abcbuÖganeiovÄnameÜavmpßvmea€µnvapeapmaebn".to_string()];
check_round_trip(vec);
}
@ -720,70 +702,82 @@ mod tests {
#[test]
fn test_struct() {
check_round_trip(vec![Struct {
a: (),
b: 10,
c: 11,
d: 12,
e: 13,
f: 14,
a: (),
b: 10,
c: 11,
d: 12,
e: 13,
f: 14,
g: 15,
h: 16,
i: 17,
j: 18,
k: 19,
g: 15,
h: 16,
i: 17,
j: 18,
k: 19,
l: 'x',
m: "abc".to_string(),
n: 20.5,
o: 21.5,
p: false,
q: None,
}]);
l: 'x',
m: "abc".to_string(),
n: 20.5,
o: 21.5,
p: false,
q: None,
}]);
check_round_trip(vec![Struct {
a: (),
b: 101,
c: 111,
d: 121,
e: 131,
f: 141,
a: (),
b: 101,
c: 111,
d: 121,
e: 131,
f: 141,
g: -15,
h: -16,
i: -17,
j: -18,
k: -19,
g: -15,
h: -16,
i: -17,
j: -18,
k: -19,
l: 'y',
m: "def".to_string(),
n: -20.5,
o: -21.5,
p: true,
q: Some(1234567),
}]);
l: 'y',
m: "def".to_string(),
n: -20.5,
o: -21.5,
p: true,
q: Some(1234567),
}]);
}
#[derive(PartialEq, Clone, Debug, RustcEncodable, RustcDecodable)]
enum Enum {
Variant1,
Variant2(usize, f32),
Variant3 { a: i32, b: char, c: bool }
Variant3 {
a: i32,
b: char,
c: bool,
},
}
#[test]
fn test_enum() {
check_round_trip(vec![Enum::Variant1,
Enum::Variant2(1, 2.5),
Enum::Variant3 { a: 3, b: 'b', c: false },
Enum::Variant3 { a: -4, b: 'f', c: true }]);
Enum::Variant3 {
a: 3,
b: 'b',
c: false,
},
Enum::Variant3 {
a: -4,
b: 'f',
c: true,
}]);
}
#[test]
fn test_sequence() {
let mut vec = vec![];
for i in -100i64 .. 100i64 {
vec.push(i*100000);
for i in -100i64..100i64 {
vec.push(i * 100000);
}
check_round_trip(vec![vec]);
@ -793,8 +787,8 @@ mod tests {
fn test_hash_map() {
use std::collections::HashMap;
let mut map = HashMap::new();
for i in -100i64 .. 100i64 {
map.insert(i*100000, i*10000);
for i in -100i64..100i64 {
map.insert(i * 100000, i * 10000);
}
check_round_trip(vec![map]);