about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-02-21 14:18:39 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-02-24 09:51:39 -0800
commit6485917d7ca832ee8867c6a7a55af3ed1e9d304c (patch)
treeb5c5ce62644376eae2ebb150c5d14a8eb34fe5fb
parent672097753a217d4990129cbdfab16ef8c9b08b21 (diff)
downloadrust-6485917d7ca832ee8867c6a7a55af3ed1e9d304c.tar.gz
rust-6485917d7ca832ee8867c6a7a55af3ed1e9d304c.zip
Move extra::json to libserialize
This also inverts the dependency between libserialize and libcollections.

cc #8784
-rw-r--r--mk/crates.mk6
-rw-r--r--src/doc/rust.md12
-rw-r--r--src/libcollections/dlist.rs27
-rw-r--r--src/libcollections/enum_set.rs2
-rw-r--r--src/libcollections/hashmap.rs67
-rw-r--r--src/libcollections/lib.rs1
-rw-r--r--src/libcollections/ringbuf.rs27
-rw-r--r--src/libcollections/treemap.rs67
-rw-r--r--src/libcollections/trie.rs55
-rw-r--r--src/libextra/lib.rs10
-rw-r--r--src/libextra/workcache.rs4
-rw-r--r--src/libnum/lib.rs2
-rw-r--r--src/librustc/driver/driver.rs3
-rw-r--r--src/librustdoc/html/render.rs2
-rw-r--r--src/librustdoc/lib.rs3
-rw-r--r--src/librustdoc/plugins.rs2
-rw-r--r--src/libserialize/collection_impls.rs281
-rw-r--r--src/libserialize/json.rs (renamed from src/libextra/json.rs)55
-rw-r--r--src/libserialize/lib.rs7
-rw-r--r--src/libsyntax/ast.rs3
-rw-r--r--src/libsyntax/parse/mod.rs4
-rw-r--r--src/libtest/lib.rs5
-rw-r--r--src/test/run-pass/extern-mod-syntax.rs4
-rw-r--r--src/test/run-pass/issue-2804.rs14
-rw-r--r--src/test/run-pass/issue-4016.rs4
-rw-r--r--src/test/run-pass/issue-4036.rs4
26 files changed, 340 insertions, 331 deletions
diff --git a/mk/crates.mk b/mk/crates.mk
index 8e624cb313f..fadbaf5a6c8 100644
--- a/mk/crates.mk
+++ b/mk/crates.mk
@@ -68,15 +68,15 @@ DEPS_rustdoc := rustc native:sundown serialize sync getopts collections \
 DEPS_flate := std native:miniz
 DEPS_arena := std collections
 DEPS_glob := std
-DEPS_serialize := std
+DEPS_serialize := std collections
 DEPS_term := std collections
 DEPS_semver := std
 DEPS_uuid := std serialize
 DEPS_sync := std
 DEPS_getopts := std
-DEPS_collections := std serialize
+DEPS_collections := std
 DEPS_fourcc := syntax std
-DEPS_num := std extra
+DEPS_num := std
 DEPS_test := std extra collections getopts serialize term
 DEPS_time := std serialize
 
diff --git a/src/doc/rust.md b/src/doc/rust.md
index 650bee7d335..9bc394abf5e 100644
--- a/src/doc/rust.md
+++ b/src/doc/rust.md
@@ -875,16 +875,16 @@ An example of what will and will not work for `use` items:
 
 ~~~~
 # #[allow(unused_imports)];
-use foo::extra::json;    // good: foo is at the root of the crate
+use foo::native::start;  // good: foo is at the root of the crate
 use foo::baz::foobaz;    // good: foo is at the root of the crate
 
 mod foo {
-    extern crate extra;
+    extern crate native;
 
-    use foo::extra::json;  // good: foo is at crate root
-//  use extra::json::*;    // bad:  extra is not at the crate root
-    use self::baz::foobaz; // good: self refers to module 'foo'
-    use foo::bar::foobar;  // good: foo is at crate root
+    use foo::native::start; // good: foo is at crate root
+//  use native::start;      // bad:  native is not at the crate root
+    use self::baz::foobaz;  // good: self refers to module 'foo'
+    use foo::bar::foobar;   // good: foo is at crate root
 
     pub mod bar {
         pub fn foobar() { }
diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs
index 591561d775e..4a4ec01f6d2 100644
--- a/src/libcollections/dlist.rs
+++ b/src/libcollections/dlist.rs
@@ -30,8 +30,6 @@ use std::iter;
 
 use deque::Deque;
 
-use serialize::{Encodable, Decodable, Encoder, Decoder};
-
 /// A doubly-linked list.
 pub struct DList<T> {
     priv length: uint,
@@ -630,31 +628,6 @@ impl<A: Clone> Clone for 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 {
     extern crate test;
diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs
index 2bd8cbf03e9..f33d77ba682 100644
--- a/src/libcollections/enum_set.rs
+++ b/src/libcollections/enum_set.rs
@@ -15,7 +15,7 @@
 
 use std::num::Bitwise;
 
-#[deriving(Clone, Eq, Hash, Show, Encodable, Decodable)]
+#[deriving(Clone, Eq, Hash, Show)]
 /// A specialized Set implementation to use enum types.
 pub struct EnumSet<E> {
     // We must maintain the invariant that no bits are set
diff --git a/src/libcollections/hashmap.rs b/src/libcollections/hashmap.rs
index 877f2b30009..4f0b7dfb35d 100644
--- a/src/libcollections/hashmap.rs
+++ b/src/libcollections/hashmap.rs
@@ -65,8 +65,6 @@ use std::vec::{Items, MutItems};
 use std::vec_ng::Vec;
 use std::vec_ng;
 
-use serialize::{Encodable, Decodable, Encoder, Decoder};
-
 static INITIAL_CAPACITY: uint = 32u; // 2^5
 
 struct Bucket<K,V> {
@@ -912,71 +910,6 @@ pub type SetAlgebraItems<'a, T> =
     FilterMap<'static,(&'a HashSet<T>, &'a T), &'a T,
               Zip<Repeat<&'a HashSet<T>>,SetItems<'a,T>>>;
 
-impl<
-    E: Encoder,
-    K: Encodable<E> + Hash + Eq,
-    V: Encodable<E>
-> Encodable<E> for HashMap<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> + Hash + Eq,
-    V: Decodable<D>
-> Decodable<D> for HashMap<K, V> {
-    fn decode(d: &mut D) -> HashMap<K, V> {
-        d.read_map(|d, len| {
-            let mut map = HashMap::with_capacity(len);
-            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> + Hash + Eq
-> Encodable<S> for HashSet<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> + Hash + Eq
-> Decodable<D> for HashSet<T> {
-    fn decode(d: &mut D) -> HashSet<T> {
-        d.read_seq(|d, len| {
-            let mut set = HashSet::with_capacity(len);
-            for i in range(0u, len) {
-                set.insert(d.read_seq_elt(i, |d| Decodable::decode(d)));
-            }
-            set
-        })
-    }
-}
-
 #[cfg(test)]
 mod test_map {
     use super::{HashMap, HashSet};
diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs
index dd42c2a0dd0..14aee6653ac 100644
--- a/src/libcollections/lib.rs
+++ b/src/libcollections/lib.rs
@@ -19,7 +19,6 @@
 
 #[feature(macro_rules, managed_boxes)];
 
-extern crate serialize;
 #[cfg(test)] extern crate test;
 
 pub use bitv::Bitv;
diff --git a/src/libcollections/ringbuf.rs b/src/libcollections/ringbuf.rs
index 8abc5a3ca11..4b97bfbd18d 100644
--- a/src/libcollections/ringbuf.rs
+++ b/src/libcollections/ringbuf.rs
@@ -19,8 +19,6 @@ use std::iter::{Rev, RandomAccessIterator};
 
 use deque::Deque;
 
-use serialize::{Encodable, Decodable, Encoder, Decoder};
-
 static INITIAL_CAPACITY: uint = 8u; // 2^3
 static MINIMUM_CAPACITY: uint = 2u;
 
@@ -404,31 +402,6 @@ impl<A> Extendable<A> for RingBuf<A> {
     }
 }
 
-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 {
     extern crate test;
diff --git a/src/libcollections/treemap.rs b/src/libcollections/treemap.rs
index a4b23579606..6388b4c7c52 100644
--- a/src/libcollections/treemap.rs
+++ b/src/libcollections/treemap.rs
@@ -17,8 +17,6 @@ use std::cmp::Ordering;
 use std::mem::{replace, swap};
 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
@@ -1006,71 +1004,6 @@ impl<T: TotalOrd> Extendable<T> for TreeSet<T> {
     }
 }
 
-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 {
 
diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs
index 022a64fbb7a..5d285e7d29e 100644
--- a/src/libcollections/trie.rs
+++ b/src/libcollections/trie.rs
@@ -16,8 +16,6 @@ use std::mem::init;
 use std::vec;
 use std::vec::{Items, MutItems};
 
-use serialize::{Encodable, Decodable, Encoder, Decoder};
-
 // FIXME: #5244: need to manually update the TrieNode constructor
 static SHIFT: uint = 4;
 static SIZE: uint = 1 << SHIFT;
@@ -620,59 +618,6 @@ impl<'a> Iterator<uint> for SetItems<'a> {
     }
 }
 
-impl<
-    E: Encoder,
-    V: Encodable<E>
-> Encodable<E> for TrieMap<V> {
-    fn encode(&self, e: &mut E) {
-        e.emit_map(self.len(), |e| {
-                for (i, (key, val)) in self.iter().enumerate() {
-                    e.emit_map_elt_key(i, |e| key.encode(e));
-                    e.emit_map_elt_val(i, |e| val.encode(e));
-                }
-            });
-    }
-}
-
-impl<
-    D: Decoder,
-    V: Decodable<D>
-> Decodable<D> for TrieMap<V> {
-    fn decode(d: &mut D) -> TrieMap<V> {
-        d.read_map(|d, len| {
-            let mut map = TrieMap::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> Encodable<S> for TrieSet {
-    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> Decodable<D> for TrieSet {
-    fn decode(d: &mut D) -> TrieSet {
-        d.read_seq(|d, len| {
-            let mut set = TrieSet::new();
-            for i in range(0u, len) {
-                set.insert(d.read_seq_elt(i, |d| Decodable::decode(d)));
-            }
-            set
-        })
-    }
-}
-
 #[cfg(test)]
 mod test_map {
     use super::{TrieMap, TrieNode, Internal, External};
diff --git a/src/libextra/lib.rs b/src/libextra/lib.rs
index ac40b504f0c..ba26e0c44fa 100644
--- a/src/libextra/lib.rs
+++ b/src/libextra/lib.rs
@@ -42,19 +42,9 @@ extern crate time;
 // Utility modules
 pub mod c_vec;
 pub mod url;
-pub mod json;
 pub mod tempfile;
 pub mod workcache;
 pub mod stats;
 
 #[cfg(unicode)]
 mod unicode;
-
-// A curious inner-module that's not exported that contains the binding
-// 'extra' so that macro-expanded references to extra::serialize and such
-// can be resolved within libextra.
-#[doc(hidden)]
-pub mod extra {
-    pub use serialize;
-}
-
diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs
index 133e5bc71f8..97c0f786071 100644
--- a/src/libextra/workcache.rs
+++ b/src/libextra/workcache.rs
@@ -10,8 +10,8 @@
 
 #[allow(missing_doc)];
 
-use json;
-use json::ToJson;
+use serialize::json;
+use serialize::json::ToJson;
 use serialize::{Encoder, Encodable, Decoder, Decodable};
 use sync::{Arc,RWArc};
 use collections::TreeMap;
diff --git a/src/libnum/lib.rs b/src/libnum/lib.rs
index e9e93cc29d6..8e42b01f14c 100644
--- a/src/libnum/lib.rs
+++ b/src/libnum/lib.rs
@@ -15,8 +15,6 @@
 #[crate_type = "dylib"];
 #[license = "MIT/ASL2"];
 
-extern crate extra;
-
 pub mod bigint;
 pub mod rational;
 pub mod complex;
diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs
index 1f7a75da345..6f90ed81924 100644
--- a/src/librustc/driver/driver.rs
+++ b/src/librustc/driver/driver.rs
@@ -27,8 +27,7 @@ use middle;
 use util::common::time;
 use util::ppaux;
 
-use extra::json;
-use serialize::Encodable;
+use serialize::{json, Encodable};
 
 use std::cell::{Cell, RefCell};
 use std::io;
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 040d2b3b914..d52389f15a3 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -42,7 +42,7 @@ use std::vec;
 use collections::{HashMap, HashSet};
 
 use sync::Arc;
-use extra::json::ToJson;
+use serialize::json::ToJson;
 use syntax::ast;
 use syntax::attr;
 use syntax::parse::token::InternedString;
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index 51edf4fdff4..19e3aed6462 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -30,8 +30,7 @@ use std::local_data;
 use std::io;
 use std::io::{File, MemWriter};
 use std::str;
-use extra::json;
-use serialize::{Decodable, Encodable};
+use serialize::{json, Decodable, Encodable};
 
 pub mod clean;
 pub mod core;
diff --git a/src/librustdoc/plugins.rs b/src/librustdoc/plugins.rs
index db714376646..2e7c4224ee1 100644
--- a/src/librustdoc/plugins.rs
+++ b/src/librustdoc/plugins.rs
@@ -10,7 +10,7 @@
 
 use clean;
 
-use extra::json;
+use serialize::json;
 use dl = std::unstable::dynamic_lib;
 
 pub type PluginJson = Option<(~str, json::Json)>;
diff --git a/src/libserialize/collection_impls.rs b/src/libserialize/collection_impls.rs
new file mode 100644
index 00000000000..43200a99047
--- /dev/null
+++ b/src/libserialize/collection_impls.rs
@@ -0,0 +1,281 @@
+// Copyright 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.
+
+//! Implementations of serialization for structures found in libcollections
+
+use std::uint;
+use std::hash::Hash;
+
+use {Decodable, Encodable, Decoder, Encoder};
+use collections::{DList, RingBuf, TreeMap, TreeSet, Deque, HashMap, HashSet,
+                  TrieMap, TrieSet};
+use collections::enum_set::{EnumSet, CLike};
+
+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> + 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
+        })
+    }
+}
+
+impl<
+    S: Encoder,
+    T: Encodable<S> + CLike
+> Encodable<S> for EnumSet<T> {
+    fn encode(&self, s: &mut S) {
+        let mut bits = 0;
+        for item in self.iter() {
+            bits |= item.to_uint();
+        }
+        s.emit_uint(bits);
+    }
+}
+
+impl<
+    D: Decoder,
+    T: Decodable<D> + CLike
+> Decodable<D> for EnumSet<T> {
+    fn decode(d: &mut D) -> EnumSet<T> {
+        let bits = d.read_uint();
+        let mut set = EnumSet::empty();
+        for bit in range(0, uint::BITS) {
+            if bits & (1 << bit) != 0 {
+                set.add(CLike::from_uint(1 << bit));
+            }
+        }
+        set
+    }
+}
+
+impl<
+    E: Encoder,
+    K: Encodable<E> + Hash + Eq,
+    V: Encodable<E>
+> Encodable<E> for HashMap<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> + Hash + Eq,
+    V: Decodable<D>
+> Decodable<D> for HashMap<K, V> {
+    fn decode(d: &mut D) -> HashMap<K, V> {
+        d.read_map(|d, len| {
+            let mut map = HashMap::with_capacity(len);
+            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> + Hash + Eq
+> Encodable<S> for HashSet<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> + Hash + Eq
+> Decodable<D> for HashSet<T> {
+    fn decode(d: &mut D) -> HashSet<T> {
+        d.read_seq(|d, len| {
+            let mut set = HashSet::with_capacity(len);
+            for i in range(0u, len) {
+                set.insert(d.read_seq_elt(i, |d| Decodable::decode(d)));
+            }
+            set
+        })
+    }
+}
+
+impl<
+    E: Encoder,
+    V: Encodable<E>
+> Encodable<E> for TrieMap<V> {
+    fn encode(&self, e: &mut E) {
+        e.emit_map(self.len(), |e| {
+                for (i, (key, val)) in self.iter().enumerate() {
+                    e.emit_map_elt_key(i, |e| key.encode(e));
+                    e.emit_map_elt_val(i, |e| val.encode(e));
+                }
+            });
+    }
+}
+
+impl<
+    D: Decoder,
+    V: Decodable<D>
+> Decodable<D> for TrieMap<V> {
+    fn decode(d: &mut D) -> TrieMap<V> {
+        d.read_map(|d, len| {
+            let mut map = TrieMap::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> Encodable<S> for TrieSet {
+    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> Decodable<D> for TrieSet {
+    fn decode(d: &mut D) -> TrieSet {
+        d.read_seq(|d, len| {
+            let mut set = TrieSet::new();
+            for i in range(0u, len) {
+                set.insert(d.read_seq_elt(i, |d| Decodable::decode(d)));
+            }
+            set
+        })
+    }
+}
diff --git a/src/libextra/json.rs b/src/libserialize/json.rs
index d438b00b992..be13a8d0696 100644
--- a/src/libextra/json.rs
+++ b/src/libserialize/json.rs
@@ -59,11 +59,8 @@ the code for these traits: `#[deriving(Decodable, Encodable)]`
 To encode using Encodable :
 
 ```rust
-extern crate extra;
-extern crate serialize;
-use extra::json;
 use std::io;
-use serialize::Encodable;
+use serialize::{json, Encodable};
 
  #[deriving(Encodable)]
  pub struct TestStruct   {
@@ -84,7 +81,7 @@ Two wrapper functions are provided to encode a Encodable object
 into a string (~str) or buffer (~[u8]): `str_encode(&m)` and `buffer_encode(&m)`.
 
 ```rust
-use extra::json;
+use serialize::json;
 let to_encode_object = ~"example of string to encode";
 let encoded_str: ~str = json::Encoder::str_encode(&to_encode_object);
 ```
@@ -99,11 +96,11 @@ A basic `ToJson` example using a TreeMap of attribute name / attribute value:
 
 
 ```rust
-extern crate extra;
 extern crate collections;
+extern crate serialize;
 
-use extra::json;
-use extra::json::ToJson;
+use serialize::json;
+use serialize::json::ToJson;
 use collections::TreeMap;
 
 pub struct MyStruct  {
@@ -130,9 +127,8 @@ fn main() {
 To decode a JSON string using `Decodable` trait :
 
 ```rust
-extern crate extra;
 extern crate serialize;
-use serialize::Decodable;
+use serialize::{json, Decodable};
 
 #[deriving(Decodable)]
 pub struct MyStruct  {
@@ -143,8 +139,8 @@ pub struct MyStruct  {
 fn main() {
     let json_str_to_decode: ~str =
             ~"{\"attr1\":1,\"attr2\":\"toto\"}";
-    let json_object = extra::json::from_str(json_str_to_decode);
-    let mut decoder = extra::json::Decoder::new(json_object.unwrap());
+    let json_object = json::from_str(json_str_to_decode);
+    let mut decoder = json::Decoder::new(json_object.unwrap());
     let decoded_object: MyStruct = Decodable::decode(&mut decoder); // create the final object
 }
 ```
@@ -157,10 +153,8 @@ Create a struct called TestStruct1 and serialize and deserialize it to and from
 using the serialization API, using the derived serialization code.
 
 ```rust
-extern crate extra;
 extern crate serialize;
-use extra::json;
-use serialize::{Encodable, Decodable};
+use serialize::{json, Encodable, Decodable};
 
  #[deriving(Decodable, Encodable)] //generate Decodable, Encodable impl.
  pub struct TestStruct1  {
@@ -176,9 +170,9 @@ fn main() {
          {data_int: 1, data_str:~"toto", data_vector:~[2,3,4,5]};
     let encoded_str: ~str = json::Encoder::str_encode(&to_encode_object);
 
-    // To deserialize use the `extra::json::from_str` and `extra::json::Decoder`
+    // To deserialize use the `json::from_str` and `json::Decoder`
 
-    let json_object = extra::json::from_str(encoded_str);
+    let json_object = json::from_str(encoded_str);
     let mut decoder = json::Decoder::new(json_object.unwrap());
     let decoded1: TestStruct1 = Decodable::decode(&mut decoder); // create the final object
 }
@@ -190,13 +184,11 @@ This example use the ToJson impl to deserialize the JSON string.
 Example of `ToJson` trait implementation for TestStruct1.
 
 ```rust
-extern crate extra;
 extern crate serialize;
 extern crate collections;
 
-use extra::json;
-use extra::json::ToJson;
-use serialize::{Encodable, Decodable};
+use serialize::json::ToJson;
+use serialize::{json, Encodable, Decodable};
 use collections::TreeMap;
 
 #[deriving(Decodable, Encodable)] // generate Decodable, Encodable impl.
@@ -242,8 +234,7 @@ use std::num;
 use std::str;
 use std::fmt;
 
-use serialize::Encodable;
-use serialize;
+use Encodable;
 use collections::TreeMap;
 
 macro_rules! try( ($e:expr) => (
@@ -324,7 +315,7 @@ impl<'a> Encoder<'a> {
     }
 
     /// Encode the specified struct into a json [u8]
-    pub fn buffer_encode<T:serialize::Encodable<Encoder<'a>>>(to_encode_object: &T) -> ~[u8]  {
+    pub fn buffer_encode<T:Encodable<Encoder<'a>>>(to_encode_object: &T) -> ~[u8]  {
        //Serialize the object in a string using a writer
         let mut m = MemWriter::new();
         {
@@ -335,13 +326,13 @@ impl<'a> Encoder<'a> {
     }
 
     /// Encode the specified struct into a json str
-    pub fn str_encode<T:serialize::Encodable<Encoder<'a>>>(to_encode_object: &T) -> ~str  {
+    pub fn str_encode<T:Encodable<Encoder<'a>>>(to_encode_object: &T) -> ~str  {
         let buff:~[u8] = Encoder::buffer_encode(to_encode_object);
         str::from_utf8_owned(buff).unwrap()
     }
 }
 
-impl<'a> serialize::Encoder for Encoder<'a> {
+impl<'a> ::Encoder for Encoder<'a> {
     fn emit_nil(&mut self) { try!(write!(self.wr, "null")) }
 
     fn emit_uint(&mut self, v: uint) { self.emit_f64(v as f64); }
@@ -502,7 +493,7 @@ impl<'a> PrettyEncoder<'a> {
     }
 }
 
-impl<'a> serialize::Encoder for PrettyEncoder<'a> {
+impl<'a> ::Encoder for PrettyEncoder<'a> {
     fn emit_nil(&mut self) { try!(write!(self.wr, "null")); }
 
     fn emit_uint(&mut self, v: uint) { self.emit_f64(v as f64); }
@@ -683,7 +674,7 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {
     }
 }
 
-impl<E: serialize::Encoder> serialize::Encodable<E> for Json {
+impl<E: ::Encoder> Encodable<E> for Json {
     fn encode(&self, e: &mut E) {
         match *self {
             Number(v) => v.encode(e),
@@ -1154,7 +1145,7 @@ impl Decoder {
     }
 }
 
-impl serialize::Decoder for Decoder {
+impl ::Decoder for Decoder {
     fn read_nil(&mut self) -> () {
         debug!("read_nil");
         match self.stack.pop().unwrap() {
@@ -1591,10 +1582,10 @@ impl fmt::Show for Error {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
-
+    use {Encodable, Decodable};
+    use super::{Encoder, Decoder, Error, Boolean, Number, List, String, Null,
+                PrettyEncoder, Object, Json, from_str};
     use std::io;
-    use serialize::{Encodable, Decodable};
     use collections::TreeMap;
 
     #[deriving(Eq, Encodable, Decodable)]
diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs
index f89f56c0f34..f8bb39bd34d 100644
--- a/src/libserialize/lib.rs
+++ b/src/libserialize/lib.rs
@@ -26,12 +26,15 @@ Core encoding and decoding interfaces.
 #[cfg(test)]
 extern crate test;
 
+extern crate collections;
+
 pub use self::serialize::{Decoder, Encoder, Decodable, Encodable,
-    DecoderHelpers, EncoderHelpers};
+                          DecoderHelpers, EncoderHelpers};
 
 mod serialize;
+mod collection_impls;
 
 pub mod base64;
 pub mod ebml;
 pub mod hex;
-
+pub mod json;
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 7561d8cbbae..0415748097c 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -1201,8 +1201,7 @@ pub enum InlinedItem {
 
 #[cfg(test)]
 mod test {
-    extern crate extra;
-    use self::extra::json;
+    use serialize::json;
     use serialize;
     use codemap::*;
     use super::*;
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs
index 08aec075770..9d0c9d0f4d3 100644
--- a/src/libsyntax/parse/mod.rs
+++ b/src/libsyntax/parse/mod.rs
@@ -283,10 +283,8 @@ pub fn maybe_aborted<T>(result: T, mut p: Parser) -> T {
 
 #[cfg(test)]
 mod test {
-    extern crate extra;
-    use self::extra::json;
     use super::*;
-    use serialize::Encodable;
+    use serialize::{json, Encodable};
     use std::io;
     use std::io::MemWriter;
     use std::str;
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs
index c0c62d93b39..6093948d9f4 100644
--- a/src/libtest/lib.rs
+++ b/src/libtest/lib.rs
@@ -29,13 +29,12 @@ extern crate term;
 extern crate time;
 
 use collections::TreeMap;
-use extra::json::ToJson;
-use extra::json;
 use extra::stats::Stats;
 use extra::stats;
 use time::precise_time_ns;
 use getopts::{OptGroup, optflag, optopt};
-use serialize::Decodable;
+use serialize::{json, Decodable};
+use serialize::json::ToJson;
 use term::Terminal;
 use term::color::{Color, RED, YELLOW, GREEN, CYAN};
 
diff --git a/src/test/run-pass/extern-mod-syntax.rs b/src/test/run-pass/extern-mod-syntax.rs
index fdea2716d5f..e31a9e3f7f5 100644
--- a/src/test/run-pass/extern-mod-syntax.rs
+++ b/src/test/run-pass/extern-mod-syntax.rs
@@ -12,8 +12,8 @@
 
 #[allow(unused_imports)];
 
-extern crate extra;
-use extra::json::Object;
+extern crate serialize;
+use serialize::json::Object;
 
 pub fn main() {
     println!("Hello world!");
diff --git a/src/test/run-pass/issue-2804.rs b/src/test/run-pass/issue-2804.rs
index a1bed266817..8370e0f7f9c 100644
--- a/src/test/run-pass/issue-2804.rs
+++ b/src/test/run-pass/issue-2804.rs
@@ -11,10 +11,10 @@
 // except according to those terms.
 
 extern crate collections;
-extern crate extra;
+extern crate serialize;
 
-use extra::json;
 use collections::HashMap;
+use serialize::json;
 use std::option;
 
 enum object {
@@ -25,7 +25,7 @@ enum object {
 fn lookup(table: ~json::Object, key: ~str, default: ~str) -> ~str
 {
     match table.find(&key) {
-        option::Some(&extra::json::String(ref s)) => {
+        option::Some(&json::String(ref s)) => {
             (*s).clone()
         }
         option::Some(value) => {
@@ -38,10 +38,10 @@ fn lookup(table: ~json::Object, key: ~str, default: ~str) -> ~str
     }
 }
 
-fn add_interface(_store: int, managed_ip: ~str, data: extra::json::Json) -> (~str, object)
+fn add_interface(_store: int, managed_ip: ~str, data: json::Json) -> (~str, object)
 {
     match &data {
-        &extra::json::Object(ref interface) => {
+        &json::Object(ref interface) => {
             let name = lookup((*interface).clone(), ~"ifDescr", ~"");
             let label = format!("{}-{}", managed_ip, name);
 
@@ -54,12 +54,12 @@ fn add_interface(_store: int, managed_ip: ~str, data: extra::json::Json) -> (~st
     }
 }
 
-fn add_interfaces(store: int, managed_ip: ~str, device: HashMap<~str, extra::json::Json>)
+fn add_interfaces(store: int, managed_ip: ~str, device: HashMap<~str, json::Json>)
 -> ~[(~str, object)]
 {
     match device.get(&~"interfaces")
     {
-        &extra::json::List(ref interfaces) =>
+        &json::List(ref interfaces) =>
         {
           interfaces.map(|interface| {
                 add_interface(store, managed_ip.clone(), (*interface).clone())
diff --git a/src/test/run-pass/issue-4016.rs b/src/test/run-pass/issue-4016.rs
index 9c472e9c39a..4b9a2353862 100644
--- a/src/test/run-pass/issue-4016.rs
+++ b/src/test/run-pass/issue-4016.rs
@@ -11,11 +11,9 @@
 
 // ignore-fast
 
-extern crate extra;
 extern crate serialize;
 
-use extra::json;
-use serialize::Decodable;
+use serialize::{json, Decodable};
 
 trait JD : Decodable<json::Decoder> { }
 
diff --git a/src/test/run-pass/issue-4036.rs b/src/test/run-pass/issue-4036.rs
index 3b9cabf664a..0298a2a324f 100644
--- a/src/test/run-pass/issue-4036.rs
+++ b/src/test/run-pass/issue-4036.rs
@@ -13,10 +13,8 @@
 // Issue #4036: Test for an issue that arose around fixing up type inference
 // byproducts in vtable records.
 
-extern crate extra;
 extern crate serialize;
-use extra::json;
-use serialize::Decodable;
+use serialize::{json, Decodable};
 
 pub fn main() {
     let json = json::from_str("[1]").unwrap();