lib{serialize, uuid}: Fix snake case errors.
A number of functions/methods have been moved or renamed to align better with rust standard conventions. serialize::ebml::reader::Doc => seriaize::ebml::Doc::new serialize::ebml::reader::Decoder => Decoder::new serialize::ebml::writer::Encoder => Encoder::new [breaking-change]
This commit is contained in:
parent
3faa6762c1
commit
ed5bf6621e
|
@ -26,6 +26,10 @@ pub struct Doc<'a> {
|
|||
}
|
||||
|
||||
impl<'doc> Doc<'doc> {
|
||||
pub fn new(data: &'doc [u8]) -> Doc<'doc> {
|
||||
Doc { data: data, start: 0u, end: data.len() }
|
||||
}
|
||||
|
||||
pub fn get<'a>(&'a self, tag: uint) -> Doc<'a> {
|
||||
reader::get_doc(*self, tag)
|
||||
}
|
||||
|
@ -192,10 +196,6 @@ pub mod reader {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn Doc<'a>(data: &'a [u8]) -> Doc<'a> {
|
||||
Doc { data: data, start: 0u, end: data.len() }
|
||||
}
|
||||
|
||||
pub fn doc_at<'a>(data: &'a [u8], start: uint) -> DecodeResult<TaggedDoc<'a>> {
|
||||
let elt_tag = try!(vuint_at(data, start));
|
||||
let elt_size = try!(vuint_at(data, elt_tag.next));
|
||||
|
@ -296,14 +296,14 @@ pub mod reader {
|
|||
pos: uint,
|
||||
}
|
||||
|
||||
pub fn Decoder<'a>(d: Doc<'a>) -> Decoder<'a> {
|
||||
Decoder {
|
||||
parent: d,
|
||||
pos: d.start
|
||||
}
|
||||
}
|
||||
|
||||
impl<'doc> Decoder<'doc> {
|
||||
pub fn new(d: Doc<'doc>) -> Decoder<'doc> {
|
||||
Decoder {
|
||||
parent: d,
|
||||
pos: d.start
|
||||
}
|
||||
}
|
||||
|
||||
fn _check_label(&mut self, lbl: &str) -> DecodeResult<()> {
|
||||
if self.pos < self.parent.end {
|
||||
let TaggedDoc { tag: r_tag, doc: r_doc } =
|
||||
|
@ -673,15 +673,15 @@ pub mod writer {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn Encoder<'a, W: Writer + Seek>(w: &'a mut W) -> Encoder<'a, W> {
|
||||
Encoder {
|
||||
writer: w,
|
||||
size_positions: vec!(),
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME (#2741): Provide a function to write the standard ebml header.
|
||||
impl<'a, W: Writer + Seek> Encoder<'a, W> {
|
||||
pub fn new(w: &'a mut W) -> Encoder<'a, W> {
|
||||
Encoder {
|
||||
writer: w,
|
||||
size_positions: vec!(),
|
||||
}
|
||||
}
|
||||
|
||||
/// FIXME(pcwalton): Workaround for badness in trans. DO NOT USE ME.
|
||||
pub unsafe fn unsafe_clone(&self) -> Encoder<'a, W> {
|
||||
Encoder {
|
||||
|
@ -1020,6 +1020,7 @@ pub mod writer {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Doc;
|
||||
use ebml::reader;
|
||||
use ebml::writer;
|
||||
use {Encodable, Decodable};
|
||||
|
@ -1081,11 +1082,11 @@ mod tests {
|
|||
debug!("v == {}", v);
|
||||
let mut wr = MemWriter::new();
|
||||
{
|
||||
let mut ebml_w = writer::Encoder(&mut wr);
|
||||
let mut ebml_w = writer::Encoder::new(&mut wr);
|
||||
let _ = v.encode(&mut ebml_w);
|
||||
}
|
||||
let ebml_doc = reader::Doc(wr.get_ref());
|
||||
let mut deser = reader::Decoder(ebml_doc);
|
||||
let ebml_doc = Doc::new(wr.get_ref());
|
||||
let mut deser = reader::Decoder::new(ebml_doc);
|
||||
let v1 = Decodable::decode(&mut deser).unwrap();
|
||||
debug!("v1 == {}", v1);
|
||||
assert_eq!(v, v1);
|
||||
|
@ -1099,6 +1100,7 @@ mod tests {
|
|||
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
#![allow(non_snake_case_functions)]
|
||||
extern crate test;
|
||||
use self::test::Bencher;
|
||||
use ebml::reader;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
|
@ -795,14 +795,16 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_serialize_round_trip() {
|
||||
use serialize::ebml;
|
||||
use serialize::ebml::Doc;
|
||||
use serialize::ebml::writer::Encoder;
|
||||
use serialize::ebml::reader::Decoder;
|
||||
use serialize::{Encodable, Decodable};
|
||||
|
||||
let u = Uuid::new_v4();
|
||||
let mut wr = MemWriter::new();
|
||||
let _ = u.encode(&mut ebml::writer::Encoder(&mut wr));
|
||||
let doc = ebml::reader::Doc(wr.get_ref());
|
||||
let u2 = Decodable::decode(&mut ebml::reader::Decoder(doc)).unwrap();
|
||||
let _ = u.encode(&mut Encoder::new(&mut wr));
|
||||
let doc = Doc::new(wr.get_ref());
|
||||
let u2 = Decodable::decode(&mut Decoder::new(doc)).unwrap();
|
||||
assert_eq!(u, u2);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,12 +33,12 @@ fn test_ebml<'a, 'b, A:
|
|||
Decodable<EBReader::Decoder<'b>>
|
||||
>(a1: &A) {
|
||||
let mut wr = std::io::MemWriter::new();
|
||||
let mut ebml_w = EBWriter::Encoder(&mut wr);
|
||||
let mut ebml_w = EBwriter::Encoder::new(&mut wr);
|
||||
a1.encode(&mut ebml_w);
|
||||
let bytes = wr.get_ref();
|
||||
|
||||
let d: serialize::ebml::Doc<'a> = EBReader::Doc(bytes);
|
||||
let mut decoder: EBReader::Decoder<'a> = EBReader::Decoder(d);
|
||||
let d: serialize::ebml::Doc<'a> = EBDoc::new(bytes);
|
||||
let mut decoder: EBReader::Decoder<'a> = EBreader::Decoder::new(d);
|
||||
let a2: A = Decodable::decode(&mut decoder);
|
||||
assert!(*a1 == a2);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ use std::io::MemWriter;
|
|||
use rand::{random, Rand};
|
||||
use serialize::{Encodable, Decodable};
|
||||
use serialize::ebml;
|
||||
use serialize::ebml::Doc;
|
||||
use serialize::ebml::writer::Encoder;
|
||||
use serialize::ebml::reader::Decoder;
|
||||
|
||||
|
@ -58,10 +59,10 @@ fn roundtrip<'a, T: Rand + Eq + Encodable<Encoder<'a>> +
|
|||
Decodable<Decoder<'a>>>() {
|
||||
let obj: T = random();
|
||||
let mut w = MemWriter::new();
|
||||
let mut e = Encoder(&mut w);
|
||||
let mut e = Encoder::new(&mut w);
|
||||
obj.encode(&mut e);
|
||||
let doc = ebml::reader::Doc(@w.get_ref());
|
||||
let mut dec = Decoder(doc);
|
||||
let doc = ebml::Doc::new(@w.get_ref());
|
||||
let mut dec = Decoder::new(doc);
|
||||
let obj2 = Decodable::decode(&mut dec);
|
||||
assert!(obj == obj2);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ fn encode_ebml<'a,
|
|||
T: Encodable<writer::Encoder<'a, MemWriter>,
|
||||
std::io::IoError>>(val: &T,
|
||||
wr: &'a mut MemWriter) {
|
||||
let mut encoder = writer::Encoder(wr);
|
||||
let mut encoder = writer::Encoder::new(wr);
|
||||
val.encode(&mut encoder);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue