pull extra::{serialize, ebml} into a separate libserialize crate

- `extra::json` didn't make the cut, because of `extra::json` required
   dep on `extra::TreeMap`. If/when `extra::TreeMap` moves out of `extra`,
   then `extra::json` could move into `serialize`
- `libextra`, `libsyntax` and `librustc` depend on the newly created
  `libserialize`
- The extensions to various `extra` types like `DList`, `RingBuf`, `TreeMap`
  and `TreeSet` for `Encodable`/`Decodable` were moved into the respective
  modules in `extra`
- There is some trickery, evident in `src/libextra/lib.rs` where a stub
  of `extra::serialize` is set up (in `src/libextra/serialize.rs`) for
  use in the stage0 build, where the snapshot rustc is still making
  deriving for `Encodable` and `Decodable` point at extra. Big props to
  @huonw for help working out the re-export solution for this

extra: inline extra::serialize stub

fix stuff clobbered in rebase + don't reexport serialize::serialize

no more globs in libserialize

syntax: fix import of libserialize traits

librustc: fix bad imports in encoder/decoder

add serialize dep to librustdoc

fix failing run-pass tests w/ serialize dep

adjust uuid dep

more rebase de-clobbering for libserialize

fixing tests, pushing libextra dep into cfg(test)

fix doc code in extra::json

adjust index.md links to serialize and uuid library
This commit is contained in:
Jeff Olson 2014-02-05 08:52:54 -08:00
parent 2bf575c86f
commit b8852e89ce
30 changed files with 259 additions and 193 deletions

View File

@ -49,25 +49,26 @@
# automatically generated for all stage/host/target combinations.
################################################################################
TARGET_CRATES := std extra green rustuv native flate arena glob term semver uuid sync
TARGET_CRATES := std extra green rustuv native flate arena glob term semver uuid serialize sync
HOST_CRATES := syntax rustc rustdoc
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
TOOLS := compiletest rustdoc rustc
DEPS_std := native:rustrt
DEPS_extra := std term sync
DEPS_extra := std serialize sync term
DEPS_green := std
DEPS_rustuv := std native:uv native:uv_support
DEPS_native := std
DEPS_syntax := std extra term
DEPS_rustc := syntax native:rustllvm flate arena sync
DEPS_rustdoc := rustc native:sundown sync
DEPS_syntax := std extra term serialize
DEPS_rustc := syntax native:rustllvm flate arena serialize sync
DEPS_rustdoc := rustc native:sundown serialize sync
DEPS_flate := std native:miniz
DEPS_arena := std extra
DEPS_glob := std
DEPS_serialize := std
DEPS_term := std
DEPS_semver := std
DEPS_uuid := std extra
DEPS_uuid := std serialize
DEPS_sync := std
TOOL_DEPS_compiletest := extra green rustuv

View File

@ -41,9 +41,10 @@ li {list-style-type: none; }
* [The `flate` compression library](flate/index.html)
* [The `glob` file path matching library](glob/index.html)
* [The `semver` version collation library](semver/index.html)
* [The `term` terminal-handling library](term/index.html)
* [The UUID library](uuid/index.html)
* [The `serialize` value encoding/decoding library](serialize/index.html)
* [The `sync` library for concurrency-enabled mechanisms and primitives](sync/index.html)
* [The `term` terminal-handling library](term/index.html)
* [The `uuid` 128-bit universally unique identifier library](uuid/index.html)
# Tooling

View File

@ -30,6 +30,8 @@
use container::Deque;
use serialize::{Encodable, Decodable, Encoder, Decoder};
/// A doubly-linked list.
pub struct DList<T> {
priv length: uint,
@ -628,6 +630,31 @@ fn clone(&self) -> DList<A> {
}
}
impl<
S: Encoder,
T: Encodable<S>
> Encodable<S> for DList<T> {
fn encode(&self, s: &mut S) {
s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() {
s.emit_seq_elt(i, |s| e.encode(s));
}
})
}
}
impl<D:Decoder,T:Decodable<D>> Decodable<D> for DList<T> {
fn decode(d: &mut D) -> DList<T> {
let mut list = DList::new();
d.read_seq(|d, len| {
for i in range(0u, len) {
list.push_back(d.read_seq_elt(i, |d| Decodable::decode(d)));
}
});
list
}
}
#[cfg(test)]
mod tests {
use container::Deque;

View File

@ -51,17 +51,18 @@
Rust provides a mechanism for low boilerplate encoding & decoding
of values to and from JSON via the serialization API.
To be able to encode a piece of data, it must implement the `extra::serialize::Encodable` trait.
To be able to decode a piece of data, it must implement the `extra::serialize::Decodable` trait.
To be able to encode a piece of data, it must implement the `serialize::Encodable` trait.
To be able to decode a piece of data, it must implement the `serialize::Decodable` trait.
The Rust compiler provides an annotation to automatically generate
the code for these traits: `#[deriving(Decodable, Encodable)]`
To encode using Encodable :
```rust
extern mod serialize;
use extra::json;
use std::io;
use extra::serialize::Encodable;
use serialize::Encodable;
#[deriving(Encodable)]
pub struct TestStruct {
@ -125,7 +126,8 @@ fn main() {
To decode a json string using `Decodable` trait :
```rust
use extra::serialize::Decodable;
extern mod serialize;
use serialize::Decodable;
#[deriving(Decodable)]
pub struct MyStruct {
@ -150,8 +152,9 @@ fn main() {
using the serialization API, using the derived serialization code.
```rust
extern mod serialize;
use extra::json;
use extra::serialize::{Encodable, Decodable};
use serialize::{Encodable, Decodable};
#[deriving(Decodable, Encodable)] //generate Decodable, Encodable impl.
pub struct TestStruct1 {
@ -181,9 +184,10 @@ fn main() {
Example of `ToJson` trait implementation for TestStruct1.
```rust
extern mod serialize;
use extra::json;
use extra::json::ToJson;
use extra::serialize::{Encodable, Decodable};
use serialize::{Encodable, Decodable};
use extra::treemap::TreeMap;
#[deriving(Decodable, Encodable)] // generate Decodable, Encodable impl.
@ -312,7 +316,7 @@ pub fn new<'a>(wr: &'a mut io::Writer) -> Encoder<'a> {
}
/// Encode the specified struct into a json [u8]
pub fn buffer_encode<T:Encodable<Encoder<'a>>>(to_encode_object: &T) -> ~[u8] {
pub fn buffer_encode<T:serialize::Encodable<Encoder<'a>>>(to_encode_object: &T) -> ~[u8] {
//Serialize the object in a string using a writer
let mut m = MemWriter::new();
{
@ -323,7 +327,7 @@ pub fn buffer_encode<T:Encodable<Encoder<'a>>>(to_encode_object: &T) -> ~[u8] {
}
/// Encode the specified struct into a json str
pub fn str_encode<T:Encodable<Encoder<'a>>>(to_encode_object: &T) -> ~str {
pub fn str_encode<T:serialize::Encodable<Encoder<'a>>>(to_encode_object: &T) -> ~str {
let buff:~[u8] = Encoder::buffer_encode(to_encode_object);
str::from_utf8_owned(buff).unwrap()
}
@ -684,7 +688,7 @@ fn encode(&self, e: &mut E) {
}
}
impl Json{
impl Json {
/// Encodes a json value into a io::writer. Uses a single line.
pub fn to_writer(&self, wr: &mut io::Writer) -> io::IoResult<()> {
let mut encoder = Encoder::new(wr);

View File

@ -35,6 +35,17 @@
#[deny(missing_doc)];
extern mod sync;
#[cfg(not(stage0))]
extern mod serialize;
#[cfg(stage0)]
pub mod serialize {
#[allow(missing_doc)];
// Temp re-export until after a snapshot
extern mod serialize = "serialize";
pub use self::serialize::{Encoder, Decoder, Encodable, Decodable,
EncoderHelpers, DecoderHelpers};
}
#[cfg(stage0)]
macro_rules! if_ok (
@ -62,7 +73,6 @@ macro_rules! if_ok (
// And ... other stuff
pub mod url;
pub mod ebml;
pub mod getopts;
pub mod json;
pub mod tempfile;
@ -85,7 +95,6 @@ macro_rules! if_ok (
// Compiler support modules
pub mod test;
pub mod serialize;
// A curious inner-module that's not exported that contains the binding
// 'extra' so that macro-expanded references to extra::serialize and such

View File

@ -19,6 +19,8 @@
use container::Deque;
use serialize::{Encodable, Decodable, Encoder, Decoder};
static INITIAL_CAPACITY: uint = 8u; // 2^3
static MINIMUM_CAPACITY: uint = 2u;
@ -402,6 +404,31 @@ fn extend<T: Iterator<A>>(&mut self, iterator: &mut T) {
}
}
impl<
S: Encoder,
T: Encodable<S>
> Encodable<S> for RingBuf<T> {
fn encode(&self, s: &mut S) {
s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() {
s.emit_seq_elt(i, |s| e.encode(s));
}
})
}
}
impl<D:Decoder,T:Decodable<D>> Decodable<D> for RingBuf<T> {
fn decode(d: &mut D) -> RingBuf<T> {
let mut deque = RingBuf::new();
d.read_seq(|d, len| {
for i in range(0u, len) {
deque.push_back(d.read_seq_elt(i, |d| Decodable::decode(d)));
}
});
deque
}
}
#[cfg(test)]
mod tests {
use container::Deque;

View File

@ -17,6 +17,8 @@
use std::cmp::Ordering;
use std::ptr;
use serialize::{Encodable, Decodable, Encoder, Decoder};
// This is implemented as an AA tree, which is a simplified variation of
// a red-black tree where red (horizontal) nodes can only be added
// as a right child. The time complexity is the same, and re-balancing
@ -1004,6 +1006,71 @@ fn extend<Iter: Iterator<T>>(&mut self, iter: &mut Iter) {
}
}
impl<
E: Encoder,
K: Encodable<E> + Eq + TotalOrd,
V: Encodable<E> + Eq
> Encodable<E> for TreeMap<K, V> {
fn encode(&self, e: &mut E) {
e.emit_map(self.len(), |e| {
let mut i = 0;
for (key, val) in self.iter() {
e.emit_map_elt_key(i, |e| key.encode(e));
e.emit_map_elt_val(i, |e| val.encode(e));
i += 1;
}
})
}
}
impl<
D: Decoder,
K: Decodable<D> + Eq + TotalOrd,
V: Decodable<D> + Eq
> Decodable<D> for TreeMap<K, V> {
fn decode(d: &mut D) -> TreeMap<K, V> {
d.read_map(|d, len| {
let mut map = TreeMap::new();
for i in range(0u, len) {
let key = d.read_map_elt_key(i, |d| Decodable::decode(d));
let val = d.read_map_elt_val(i, |d| Decodable::decode(d));
map.insert(key, val);
}
map
})
}
}
impl<
S: Encoder,
T: Encodable<S> + Eq + TotalOrd
> Encodable<S> for TreeSet<T> {
fn encode(&self, s: &mut S) {
s.emit_seq(self.len(), |s| {
let mut i = 0;
for e in self.iter() {
s.emit_seq_elt(i, |s| e.encode(s));
i += 1;
}
})
}
}
impl<
D: Decoder,
T: Decodable<D> + Eq + TotalOrd
> Decodable<D> for TreeSet<T> {
fn decode(d: &mut D) -> TreeSet<T> {
d.read_seq(|d, len| {
let mut set = TreeSet::new();
for i in range(0u, len) {
set.insert(d.read_seq_elt(i, |d| Decodable::decode(d)));
}
set
})
}
}
#[cfg(test)]
mod test_treemap {

View File

@ -35,6 +35,7 @@
extern mod flate;
extern mod arena;
extern mod syntax;
extern mod serialize;
extern mod sync;
use back::link;

View File

@ -18,8 +18,8 @@
use middle::typeck;
use std::vec;
use reader = serialize::ebml::reader;
use std::rc::Rc;
use reader = extra::ebml::reader;
use syntax::ast;
use syntax::ast_map;
use syntax::diagnostic::expect;

View File

@ -31,9 +31,9 @@
use std::option;
use std::rc::Rc;
use std::vec;
use extra::ebml::reader;
use extra::ebml;
use extra::serialize::Decodable;
use serialize::ebml::reader;
use serialize::ebml;
use serialize::Decodable;
use syntax::ast_map;
use syntax::attr;
use syntax::parse::token::{IdentInterner, special_idents};

View File

@ -22,7 +22,7 @@
use middle::typeck;
use middle;
use extra::serialize::Encodable;
use serialize::Encodable;
use std::cast;
use std::cell::{Cell, RefCell};
use std::hashmap::{HashMap, HashSet};
@ -45,7 +45,7 @@
use syntax::visit::Visitor;
use syntax::visit;
use syntax;
use writer = extra::ebml::writer;
use writer = serialize::ebml::writer;
// used by astencode:
type abbrev_map = @RefCell<HashMap<ty::t, tyencode::ty_abbrev>>;

View File

@ -37,12 +37,12 @@
use std::io::Seek;
use std::rc::Rc;
use extra::ebml::reader;
use extra::ebml;
use extra::serialize;
use extra::serialize::{Encoder, Encodable, EncoderHelpers, DecoderHelpers};
use extra::serialize::{Decoder, Decodable};
use writer = extra::ebml::writer;
use serialize::ebml::reader;
use serialize::ebml;
use serialize;
use serialize::{Encoder, Encodable, EncoderHelpers, DecoderHelpers};
use serialize::{Decoder, Decodable};
use writer = serialize::ebml::writer;
#[cfg(test)] use syntax::parse;
#[cfg(test)] use syntax::print::pprust;

View File

@ -18,6 +18,7 @@
extern mod syntax;
extern mod rustc;
extern mod extra;
extern mod serialize;
extern mod sync;
use std::local_data;
@ -27,7 +28,7 @@
use extra::getopts;
use extra::getopts::groups;
use extra::json;
use extra::serialize::{Decodable, Encodable};
use serialize::{Decodable, Encodable};
use extra::time;
pub mod clean;

View File

@ -83,15 +83,19 @@ pub enum EbmlEncoderTag {
pub mod reader {
use std::char;
use super::*;
use serialize;
use std::cast::transmute;
use std::int;
use std::option::{None, Option, Some};
use std::io::extensions::u64_from_be_bytes;
use serialize;
use super::{ EsVec, EsMap, EsEnum, EsVecLen, EsVecElt, EsMapLen, EsMapKey,
EsEnumVid, EsU64, EsU32, EsU16, EsU8, EsInt, EsI64, EsI32, EsI16, EsI8,
EsBool, EsF64, EsF32, EsChar, EsStr, EsMapVal, EsEnumBody, EsUint,
EsOpaque, EsLabel, EbmlEncoderTag, Doc, TaggedDoc };
// ebml reading
pub struct Res {
@ -588,8 +592,6 @@ fn read_map_elt_val<T>(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> T)
}
pub mod writer {
use super::*;
use std::cast;
use std::clone::Clone;
use std::io;
@ -597,6 +599,13 @@ pub mod writer {
use std::io::MemWriter;
use std::io::extensions::u64_to_be_bytes;
use super::{ EsVec, EsMap, EsEnum, EsVecLen, EsVecElt, EsMapLen, EsMapKey,
EsEnumVid, EsU64, EsU32, EsU16, EsU8, EsInt, EsI64, EsI32, EsI16, EsI8,
EsBool, EsF64, EsF32, EsChar, EsStr, EsMapVal, EsEnumBody, EsUint,
EsOpaque, EsLabel, EbmlEncoderTag };
use serialize;
// ebml writing
pub struct Encoder<'a> {
// FIXME(#5665): this should take a trait object. Note that if you
@ -775,7 +784,7 @@ pub fn emit_opaque(&mut self, f: |&mut Encoder|) {
}
}
impl<'a> ::serialize::Encoder for Encoder<'a> {
impl<'a> serialize::Encoder for Encoder<'a> {
fn emit_nil(&mut self) {}
fn emit_uint(&mut self, v: uint) {
@ -952,8 +961,7 @@ fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut Encoder<'a>|) {
mod tests {
use ebml::reader;
use ebml::writer;
use serialize::Encodable;
use serialize;
use {Encodable, Decodable};
use std::io::MemWriter;
use std::option::{None, Option, Some};
@ -1017,7 +1025,7 @@ fn test_v(v: Option<int>) {
}
let ebml_doc = reader::Doc(wr.get_ref());
let mut deser = reader::Decoder(ebml_doc);
let v1 = serialize::Decodable::decode(&mut deser);
let v1 = Decodable::decode(&mut deser);
debug!("v1 == {:?}", v1);
assert_eq!(v, v1);
}
@ -1031,7 +1039,7 @@ fn test_v(v: Option<int>) {
#[cfg(test)]
mod bench {
use ebml::reader;
use test::BenchHarness;
use extra::test::BenchHarness;
#[bench]
pub fn vuint_at_A_aligned(bh: &mut BenchHarness) {

33
src/libserialize/lib.rs Normal file
View File

@ -0,0 +1,33 @@
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Support code for encoding and decoding types.
/*
Core encoding and decoding interfaces.
*/
#[crate_id = "serialize#0.10-pre"];
#[crate_type = "rlib"];
#[crate_type = "dylib"];
#[license = "MIT/ASL2"];
#[allow(missing_doc)];
#[forbid(non_camel_case_types)];
#[feature(macro_rules,managed_boxes)];
// test harness access
#[cfg(test)]
extern mod extra;
pub use self::serialize::{Decoder, Encoder, Decodable, Encodable,
DecoderHelpers, EncoderHelpers};
mod serialize;
pub mod ebml;

View File

@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@ -14,18 +14,10 @@
Core encoding and decoding interfaces.
*/
#[allow(missing_doc)];
#[forbid(non_camel_case_types)];
use std::hashmap::{HashMap, HashSet};
use std::rc::Rc;
use std::trie::{TrieMap, TrieSet};
use std::vec;
use ringbuf::RingBuf;
use container::Deque;
use dlist::DList;
use treemap::{TreeMap, TreeSet};
pub trait Encoder {
// Primitive types:
@ -614,56 +606,6 @@ fn decode(d: &mut D) -> (T0, T1, T2, T3, T4) {
}
}
impl<
S: Encoder,
T: Encodable<S>
> Encodable<S> for DList<T> {
fn encode(&self, s: &mut S) {
s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() {
s.emit_seq_elt(i, |s| e.encode(s));
}
})
}
}
impl<D:Decoder,T:Decodable<D>> Decodable<D> for DList<T> {
fn decode(d: &mut D) -> DList<T> {
let mut list = DList::new();
d.read_seq(|d, len| {
for i in range(0u, len) {
list.push_back(d.read_seq_elt(i, |d| Decodable::decode(d)));
}
});
list
}
}
impl<
S: Encoder,
T: Encodable<S>
> Encodable<S> for RingBuf<T> {
fn encode(&self, s: &mut S) {
s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() {
s.emit_seq_elt(i, |s| e.encode(s));
}
})
}
}
impl<D:Decoder,T:Decodable<D>> Decodable<D> for RingBuf<T> {
fn decode(d: &mut D) -> RingBuf<T> {
let mut deque = RingBuf::new();
d.read_seq(|d, len| {
for i in range(0u, len) {
deque.push_back(d.read_seq_elt(i, |d| Decodable::decode(d)));
}
});
deque
}
}
impl<
E: Encoder,
K: Encodable<E> + Hash + IterBytes + Eq,
@ -782,71 +724,6 @@ fn decode(d: &mut D) -> TrieSet {
}
}
impl<
E: Encoder,
K: Encodable<E> + Eq + TotalOrd,
V: Encodable<E> + Eq
> Encodable<E> for TreeMap<K, V> {
fn encode(&self, e: &mut E) {
e.emit_map(self.len(), |e| {
let mut i = 0;
for (key, val) in self.iter() {
e.emit_map_elt_key(i, |e| key.encode(e));
e.emit_map_elt_val(i, |e| val.encode(e));
i += 1;
}
})
}
}
impl<
D: Decoder,
K: Decodable<D> + Eq + TotalOrd,
V: Decodable<D> + Eq
> Decodable<D> for TreeMap<K, V> {
fn decode(d: &mut D) -> TreeMap<K, V> {
d.read_map(|d, len| {
let mut map = TreeMap::new();
for i in range(0u, len) {
let key = d.read_map_elt_key(i, |d| Decodable::decode(d));
let val = d.read_map_elt_val(i, |d| Decodable::decode(d));
map.insert(key, val);
}
map
})
}
}
impl<
S: Encoder,
T: Encodable<S> + Eq + TotalOrd
> Encodable<S> for TreeSet<T> {
fn encode(&self, s: &mut S) {
s.emit_seq(self.len(), |s| {
let mut i = 0;
for e in self.iter() {
s.emit_seq_elt(i, |s| e.encode(s));
i += 1;
}
})
}
}
impl<
D: Decoder,
T: Decodable<D> + Eq + TotalOrd
> Decodable<D> for TreeSet<T> {
fn decode(d: &mut D) -> TreeSet<T> {
d.read_seq(|d, len| {
let mut set = TreeSet::new();
for i in range(0u, len) {
set.insert(d.read_seq_elt(i, |d| Decodable::decode(d)));
}
set
})
}
}
// ___________________________________________________________________________
// Helper routines
//

View File

@ -22,7 +22,7 @@
use std::option::Option;
use std::rc::Rc;
use std::to_str::ToStr;
use extra::serialize::{Encodable, Decodable, Encoder, Decoder};
use serialize::{Encodable, Decodable, Encoder, Decoder};
/// A pointer abstraction. FIXME(eddyb) #10676 use Rc<T> in the future.
pub type P<T> = @T;
@ -1204,6 +1204,7 @@ pub enum InlinedItem {
#[cfg(test)]
mod test {
use serialize;
use extra;
use codemap::*;
use super::*;
@ -1230,6 +1231,6 @@ fn check_asts_encodable() {
},
};
// doesn't matter which encoder we use....
let _f = (@e as @extra::serialize::Encodable<extra::json::Encoder>);
let _f = (@e as @serialize::Encodable<extra::json::Encoder>);
}
}

View File

@ -23,7 +23,7 @@
use std::cell::RefCell;
use std::cmp;
use extra::serialize::{Encodable, Decodable, Encoder, Decoder};
use serialize::{Encodable, Decodable, Encoder, Decoder};
pub trait Pos {
fn from_uint(n: uint) -> Self;

View File

@ -28,12 +28,12 @@ pub fn expand_deriving_decodable(cx: &ExtCtxt,
let trait_def = TraitDef {
cx: cx, span: span,
path: Path::new_(~["extra", "serialize", "Decodable"], None,
path: Path::new_(~["serialize", "Decodable"], None,
~[~Literal(Path::new_local("__D"))], true),
additional_bounds: ~[],
generics: LifetimeBounds {
lifetimes: ~[],
bounds: ~[("__D", ~[Path::new(~["extra", "serialize", "Decoder"])])],
bounds: ~[("__D", ~[Path::new(~["serialize", "Decoder"])])],
},
methods: ~[
MethodDef {
@ -56,8 +56,7 @@ pub fn expand_deriving_decodable(cx: &ExtCtxt,
fn decodable_substructure(cx: &ExtCtxt, trait_span: Span,
substr: &Substructure) -> @Expr {
let decoder = substr.nonself_args[0];
let recurse = ~[cx.ident_of("extra"),
cx.ident_of("serialize"),
let recurse = ~[cx.ident_of("serialize"),
cx.ident_of("Decodable"),
cx.ident_of("decode")];
// throw an underscore in front to suppress unused variable warnings

View File

@ -22,7 +22,7 @@ struct Node {id: uint}
would generate two implementations like:
impl<S:extra::serialize::Encoder> Encodable<S> for Node {
impl<S:serialize::Encoder> Encodable<S> for Node {
fn encode(&self, s: &S) {
s.emit_struct("Node", 1, || {
s.emit_field("id", 0, || s.emit_uint(self.id))
@ -89,12 +89,12 @@ pub fn expand_deriving_encodable(cx: &ExtCtxt,
let trait_def = TraitDef {
cx: cx, span: span,
path: Path::new_(~["extra", "serialize", "Encodable"], None,
path: Path::new_(~["serialize", "Encodable"], None,
~[~Literal(Path::new_local("__E"))], true),
additional_bounds: ~[],
generics: LifetimeBounds {
lifetimes: ~[],
bounds: ~[("__E", ~[Path::new(~["extra", "serialize", "Encoder"])])],
bounds: ~[("__E", ~[Path::new(~["serialize", "Encoder"])])],
},
methods: ~[
MethodDef {

View File

@ -204,7 +204,7 @@ pub struct TraitDef<'a> {
/// other than the current trait
additional_bounds: ~[Ty<'a>],
/// Any extra lifetimes and/or bounds, e.g. `D: extra::serialize::Decoder`
/// Any extra lifetimes and/or bounds, e.g. `D: serialize::Decoder`
generics: LifetimeBounds<'a>,
methods: ~[MethodDef<'a>]

View File

@ -33,6 +33,7 @@
#[deny(non_camel_case_types)];
extern mod extra;
extern mod serialize;
extern mod term;
pub mod util {

View File

@ -284,7 +284,7 @@ pub fn maybe_aborted<T>(result: T, mut p: Parser) -> T {
#[cfg(test)]
mod test {
use super::*;
use extra::serialize::Encodable;
use serialize::Encodable;
use extra;
use std::io;
use std::io::MemWriter;

View File

@ -15,7 +15,7 @@
use util::interner::{RcStr, StrInterner};
use util::interner;
use extra::serialize::{Decodable, Decoder, Encodable, Encoder};
use serialize::{Decodable, Decoder, Encodable, Encoder};
use std::cast;
use std::char;
use std::fmt;

View File

@ -59,7 +59,10 @@ fn main() {
#[crate_type = "dylib"];
#[license = "MIT/ASL2"];
// test harness access
#[cfg(test)]
extern mod extra;
extern mod serialize;
use std::str;
use std::vec;
@ -73,7 +76,7 @@ fn main() {
use std::cast::{transmute,transmute_copy};
use std::to_bytes::{IterBytes, Cb};
use extra::serialize::{Encoder, Encodable, Decoder, Decodable};
use serialize::{Encoder, Encodable, Decoder, Decodable};
/// A 128-bit (16 byte) buffer containing the ID
pub type UuidBytes = [u8, ..16];
@ -784,8 +787,8 @@ fn test_rand_rand() {
#[test]
fn test_serialize_round_trip() {
use extra::ebml;
use extra::serialize::{Encodable, Decodable};
use serialize::ebml;
use serialize::{Encodable, Decodable};
let u = Uuid::new_v4();
let mut wr = MemWriter::new();

View File

@ -26,7 +26,7 @@
use std::cmp::Eq;
use std::cmp;
use std::io;
use extra::serialize::{Decodable, Encodable};
use serialize::{Decodable, Encodable};
use extra::time;
fn test_ebml<'a, A:

View File

@ -16,14 +16,14 @@
#[feature(struct_variant, managed_boxes)];
extern mod extra;
extern mod serialize;
use std::io::MemWriter;
use std::rand::{random, Rand};
use extra::serialize::{Encodable, Decodable};
use extra::ebml;
use extra::ebml::writer::Encoder;
use extra::ebml::reader::Decoder;
use serialize::{Encodable, Decodable};
use serialize::ebml;
use serialize::ebml::writer::Encoder;
use serialize::ebml::reader::Decoder;
#[deriving(Encodable, Decodable, Eq, Rand)]
struct A;

View File

@ -11,7 +11,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern mod extra; // {En,De}codable
extern mod serialize; // {En,De}codable
mod submod {
// if any of these are implemented without global calls for any
// function calls, then being in a submodule will (correctly)

View File

@ -9,10 +9,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-fast
extern mod extra;
extern mod serialize;
use extra::json;
use extra::serialize::Decodable;
use serialize::Decodable;
trait JD : Decodable<json::Decoder> { }

View File

@ -8,15 +8,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-fast
// Issue #4036: Test for an issue that arose around fixing up type inference
// byproducts in vtable records.
extern mod extra;
use self::extra::json;
use self::extra::serialize;
extern mod serialize;
use extra::json;
use serialize::Decodable;
pub fn main() {
let json = json::from_str("[1]").unwrap();
let mut decoder = json::Decoder::new(json);
let _x: ~[int] = serialize::Decodable::decode(&mut decoder);
let _x: ~[int] = Decodable::decode(&mut decoder);
}