From 50942c7695783875bd2161596036a52755ffb09c Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 19 May 2014 11:32:09 -0700 Subject: [PATCH 1/2] core: Rename `container` mod to `collections`. Closes #12543 Also renames the `Container` trait to `Collection`. [breaking-change] --- src/libcollections/bitv.rs | 2 +- src/libcollections/dlist.rs | 2 +- src/libcollections/priority_queue.rs | 2 +- src/libcollections/ringbuf.rs | 2 +- src/libcollections/smallintmap.rs | 2 +- src/libcollections/str.rs | 4 ++-- src/libcollections/string.rs | 2 +- src/libcollections/treemap.rs | 4 ++-- src/libcollections/trie.rs | 4 ++-- src/libcollections/vec.rs | 2 +- src/libcore/{container.rs => collections.rs} | 10 +++++----- src/libcore/fmt/float.rs | 2 +- src/libcore/fmt/mod.rs | 2 +- src/libcore/fmt/num.rs | 2 +- src/libcore/lib.rs | 2 +- src/libcore/prelude.rs | 2 +- src/libcore/should_not_exist.rs | 2 +- src/libcore/slice.rs | 10 +++++----- src/libcore/str.rs | 8 ++++---- src/libregex/re.rs | 2 +- src/librustc/middle/trans/adt.rs | 1 - src/librustrt/c_str.rs | 2 +- src/libstd/ascii.rs | 2 +- src/libstd/c_vec.rs | 4 ++-- src/libstd/collections/hashmap.rs | 4 ++-- src/libstd/collections/lru_cache.rs | 2 +- src/libstd/comm/sync.rs | 2 +- src/libstd/io/buffered.rs | 2 +- src/libstd/io/comm_adapters.rs | 2 +- src/libstd/io/extensions.rs | 4 ++-- src/libstd/io/fs.rs | 2 +- src/libstd/io/mem.rs | 2 +- src/libstd/io/mod.rs | 2 +- src/libstd/io/net/ip.rs | 2 +- src/libstd/lib.rs | 2 +- src/libstd/num/strconv.rs | 2 +- src/libstd/os.rs | 2 +- src/libstd/path/mod.rs | 2 +- src/libstd/path/windows.rs | 2 +- src/libstd/rt/backtrace.rs | 4 ++-- src/libsyntax/owned_slice.rs | 2 +- src/libsyntax/util/small_vector.rs | 2 +- src/test/compile-fail/map-types.rs | 4 ++-- .../run-pass/class-impl-very-parameterized-trait.rs | 2 +- src/test/run-pass/send_str_hashmap.rs | 2 +- src/test/run-pass/send_str_treemap.rs | 2 +- 46 files changed, 64 insertions(+), 65 deletions(-) rename src/libcore/{container.rs => collections.rs} (95%) diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs index 79e0c2ffea8..ac31fbbf9e4 100644 --- a/src/libcollections/bitv.rs +++ b/src/libcollections/bitv.rs @@ -857,7 +857,7 @@ impl hash::Hash for BitvSet { } } -impl Container for BitvSet { +impl Collection for BitvSet { #[inline] fn len(&self) -> uint { self.size } } diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 9d0e8e83698..f71cc7401c5 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -125,7 +125,7 @@ fn link_with_prev(mut next: Box>, prev: Rawlink>) Some(next) } -impl Container for DList { +impl Collection for DList { /// O(1) #[inline] fn is_empty(&self) -> bool { diff --git a/src/libcollections/priority_queue.rs b/src/libcollections/priority_queue.rs index 34d6bbbb665..f10c6f230ae 100644 --- a/src/libcollections/priority_queue.rs +++ b/src/libcollections/priority_queue.rs @@ -26,7 +26,7 @@ pub struct PriorityQueue { data: Vec, } -impl Container for PriorityQueue { +impl Collection for PriorityQueue { /// Returns the length of the queue fn len(&self) -> uint { self.data.len() } } diff --git a/src/libcollections/ringbuf.rs b/src/libcollections/ringbuf.rs index ce4195789fa..5708dfaf915 100644 --- a/src/libcollections/ringbuf.rs +++ b/src/libcollections/ringbuf.rs @@ -33,7 +33,7 @@ pub struct RingBuf { elts: Vec> } -impl Container for RingBuf { +impl Collection for RingBuf { /// Return the number of elements in the RingBuf fn len(&self) -> uint { self.nelts } } diff --git a/src/libcollections/smallintmap.rs b/src/libcollections/smallintmap.rs index 45584dd4b28..c61f518caa4 100644 --- a/src/libcollections/smallintmap.rs +++ b/src/libcollections/smallintmap.rs @@ -29,7 +29,7 @@ pub struct SmallIntMap { v: Vec>, } -impl Container for SmallIntMap { +impl Collection for SmallIntMap { /// Return the number of elements in the map fn len(&self) -> uint { self.v.iter().filter(|elt| elt.is_some()).count() diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 5fd133b450f..102d9c3abde 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -610,7 +610,7 @@ impl<'a> StrAllocating for MaybeOwned<'a> { } } -impl<'a> Container for MaybeOwned<'a> { +impl<'a> Collection for MaybeOwned<'a> { #[inline] fn len(&self) -> uint { self.as_slice().len() } } @@ -2036,7 +2036,7 @@ mod tests { #[test] fn test_str_container() { - fn sum_len(v: &[S]) -> uint { + fn sum_len(v: &[S]) -> uint { v.iter().map(|x| x.len()).sum() } diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index bd39c74aa84..1c1d4b98592 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -279,7 +279,7 @@ impl String { } } -impl Container for String { +impl Collection for String { #[inline] fn len(&self) -> uint { self.vec.len() diff --git a/src/libcollections/treemap.rs b/src/libcollections/treemap.rs index def1c353bc1..8d472282a68 100644 --- a/src/libcollections/treemap.rs +++ b/src/libcollections/treemap.rs @@ -86,7 +86,7 @@ impl Show for TreeMap { } } -impl Container for TreeMap { +impl Collection for TreeMap { fn len(&self) -> uint { self.length } } @@ -579,7 +579,7 @@ impl Show for TreeSet { } } -impl Container for TreeSet { +impl Collection for TreeSet { #[inline] fn len(&self) -> uint { self.map.len() } } diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs index c15a6e9e5bf..1c6b7ed9333 100644 --- a/src/libcollections/trie.rs +++ b/src/libcollections/trie.rs @@ -38,7 +38,7 @@ pub struct TrieMap { length: uint } -impl Container for TrieMap { +impl Collection for TrieMap { /// Return the number of elements in the map #[inline] fn len(&self) -> uint { self.length } @@ -285,7 +285,7 @@ pub struct TrieSet { map: TrieMap<()> } -impl Container for TrieSet { +impl Collection for TrieSet { /// Return the number of elements in the set #[inline] fn len(&self) -> uint { self.map.len() } diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 37546f64d5f..3d0182acc7e 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -393,7 +393,7 @@ impl Ord for Vec { } } -impl Container for Vec { +impl Collection for Vec { #[inline] fn len(&self) -> uint { self.len diff --git a/src/libcore/container.rs b/src/libcore/collections.rs similarity index 95% rename from src/libcore/container.rs rename to src/libcore/collections.rs index e8ee3792dcf..8ebc7c2f7fe 100644 --- a/src/libcore/container.rs +++ b/src/libcore/collections.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Traits for generic containers (including `Map` and `Set`) +//! Traits for generic collections (including `Map` and `Set`) use option::Option; /// A trait to represent the abstract idea of a container. The only concrete /// knowledge known is the number of elements contained within. -pub trait Container { +pub trait Collection { /// Return the number of elements in the container fn len(&self) -> uint; @@ -26,14 +26,14 @@ pub trait Container { } /// A trait to represent mutable containers -pub trait Mutable: Container { +pub trait Mutable: Collection { /// Clear the container, removing all values. fn clear(&mut self); } /// A map is a key-value store where values may be looked up by their keys. This /// trait provides basic operations to operate on these stores. -pub trait Map: Container { +pub trait Map: Collection { /// Return a reference to the value corresponding to the key fn find<'a>(&'a self, key: &K) -> Option<&'a V>; @@ -76,7 +76,7 @@ pub trait MutableMap: Map + Mutable { /// A set is a group of objects which are each distinct from one another. This /// trait represents actions which can be performed on sets to iterate over /// them. -pub trait Set: Container { +pub trait Set: Collection { /// Return true if the set contains a value fn contains(&self, value: &T) -> bool; diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs index e5fb148aded..f326195be16 100644 --- a/src/libcore/fmt/float.rs +++ b/src/libcore/fmt/float.rs @@ -11,7 +11,7 @@ #![allow(missing_doc)] use char; -use container::Container; +use collections::Collection; use fmt; use iter::{Iterator, range, DoubleEndedIterator}; use num::{Float, FPNaN, FPInfinite, ToPrimitive, Primitive}; diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 2cce68d5f60..37ef325d937 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -15,7 +15,7 @@ use any; use cell::Cell; use char::Char; -use container::Container; +use collections::Collection; use iter::{Iterator, range}; use kinds::Copy; use mem; diff --git a/src/libcore/fmt/num.rs b/src/libcore/fmt/num.rs index 890733dc229..f36acf344e4 100644 --- a/src/libcore/fmt/num.rs +++ b/src/libcore/fmt/num.rs @@ -14,7 +14,7 @@ #![allow(unsigned_negate)] -use container::Container; +use collections::Collection; use fmt; use iter::{Iterator, DoubleEndedIterator}; use num::{Int, cast, zero}; diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 2ccf431fc22..5661c668373 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -108,7 +108,7 @@ pub mod ptr; #[cfg(not(test))] pub mod cmp; pub mod clone; pub mod default; -pub mod container; +pub mod collections; /* Core types and methods on primitives */ diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index a6a8319ca02..df9c0e67b0d 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -47,7 +47,7 @@ pub use char::Char; pub use clone::Clone; pub use cmp::{PartialEq, PartialOrd, Eq, Ord}; pub use cmp::{Ordering, Less, Equal, Greater, Equiv}; -pub use container::{Container, Mutable, Map, MutableMap, Set, MutableSet}; +pub use collections::Collection; pub use iter::{FromIterator, Extendable}; pub use iter::{Iterator, DoubleEndedIterator, RandomAccessIterator, CloneableIterator}; pub use iter::{OrdIterator, MutableDoubleEndedIterator, ExactSize}; diff --git a/src/libcore/should_not_exist.rs b/src/libcore/should_not_exist.rs index 2c6f2978aa7..ed6b73df38d 100644 --- a/src/libcore/should_not_exist.rs +++ b/src/libcore/should_not_exist.rs @@ -25,7 +25,7 @@ // Currently, no progress has been made on this list. use clone::Clone; -use container::Container; +use collections::Collection; use finally::try_finally; use intrinsics; use iter::{range, Iterator}; diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 4dea1fd75a4..585373ec70c 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -16,7 +16,7 @@ use mem::transmute; use clone::Clone; -use container::Container; +use collections::Collection; use cmp::{PartialEq, Ord, Ordering, Less, Equal, Greater}; use cmp; use default::Default; @@ -253,7 +253,7 @@ pub mod traits { use cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering, Equiv}; use iter::order; - use container::Container; + use collections::Collection; impl<'a,T:PartialEq> PartialEq for &'a [T] { fn eq(&self, other: & &'a [T]) -> bool { @@ -347,7 +347,7 @@ impl Vector for ~[T] { fn as_slice<'a>(&'a self) -> &'a [T] { let v: &'a [T] = *self; v } } -impl<'a, T> Container for &'a [T] { +impl<'a, T> Collection for &'a [T] { /// Returns the length of a vector #[inline] fn len(&self) -> uint { @@ -355,7 +355,7 @@ impl<'a, T> Container for &'a [T] { } } -impl Container for ~[T] { +impl Collection for ~[T] { /// Returns the length of a vector #[inline] fn len(&self) -> uint { @@ -1205,7 +1205,7 @@ pub mod raw { /// Operations on `[u8]`. pub mod bytes { - use container::Container; + use collections::Collection; use ptr; use slice::MutableVector; diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 87177b4ac90..c01997f1c42 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -19,7 +19,7 @@ use char; use clone::Clone; use cmp; use cmp::{PartialEq, Eq}; -use container::Container; +use collections::Collection; use default::Default; use iter::{Filter, Map, Iterator}; use iter::{DoubleEndedIterator, ExactSize}; @@ -866,7 +866,7 @@ static TAG_CONT_U8: u8 = 128u8; /// Unsafe operations pub mod raw { use mem; - use container::Container; + use collections::Collection; use ptr::RawPtr; use raw::Slice; use slice::{ImmutableVector}; @@ -930,8 +930,8 @@ Section: Trait implementations #[cfg(not(test))] #[allow(missing_doc)] pub mod traits { - use container::Container; use cmp::{Ord, Ordering, Less, Equal, Greater, PartialEq, PartialOrd, Equiv, Eq}; + use collections::Collection; use iter::Iterator; use option::{Some, None}; use str::{Str, StrSlice, eq_slice}; @@ -987,7 +987,7 @@ impl<'a> Str for &'a str { fn as_slice<'a>(&'a self) -> &'a str { *self } } -impl<'a> Container for &'a str { +impl<'a> Collection for &'a str { #[inline] fn len(&self) -> uint { self.repr().len diff --git a/src/libregex/re.rs b/src/libregex/re.rs index fbe0359ff6f..a499c1e125d 100644 --- a/src/libregex/re.rs +++ b/src/libregex/re.rs @@ -775,7 +775,7 @@ impl<'t> Captures<'t> { } } -impl<'t> Container for Captures<'t> { +impl<'t> Collection for Captures<'t> { /// Returns the number of captured groups. #[inline] fn len(&self) -> uint { diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index 5f51f80299f..9fe403159f2 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -45,7 +45,6 @@ #![allow(unsigned_negate)] -use std::container::Map; use libc::c_ulonglong; use std::num::{Bitwise}; use std::rc::Rc; diff --git a/src/librustrt/c_str.rs b/src/librustrt/c_str.rs index 4234c085148..b4d9ac7efbe 100644 --- a/src/librustrt/c_str.rs +++ b/src/librustrt/c_str.rs @@ -229,7 +229,7 @@ impl Drop for CString { } } -impl Container for CString { +impl Collection for CString { /// Return the number of bytes in the CString (not including the NUL terminator). /// /// # Failure diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index e9bb23a75c8..b9edc9a811e 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -10,7 +10,7 @@ //! Operations on ASCII strings and characters -use container::Container; +use collections::Collection; use fmt; use iter::Iterator; use mem; diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index 817b54fb692..e8a158ad230 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -33,7 +33,7 @@ //! handled correctly, i.e. that allocated memory is eventually freed //! if necessary. -use container::Container; +use collections::Collection; use kinds::Send; use mem; use ops::Drop; @@ -149,7 +149,7 @@ impl CVec { } } -impl Container for CVec { +impl Collection for CVec { fn len(&self) -> uint { self.len } } diff --git a/src/libstd/collections/hashmap.rs b/src/libstd/collections/hashmap.rs index 571c5794704..1f3c34600bd 100644 --- a/src/libstd/collections/hashmap.rs +++ b/src/libstd/collections/hashmap.rs @@ -1504,7 +1504,7 @@ impl, S, H: Hasher> PartialEq for HashSet { impl, S, H: Hasher> Eq for HashSet {} -impl, S, H: Hasher> Container for HashSet { +impl, S, H: Hasher> Collection for HashSet { fn len(&self) -> uint { self.map.len() } } @@ -2159,8 +2159,8 @@ mod test_set { use prelude::*; use super::HashSet; - use container::Container; use slice::ImmutableEqVector; + use std::collections::Collection; #[test] fn test_disjoint() { diff --git a/src/libstd/collections/lru_cache.rs b/src/libstd/collections/lru_cache.rs index a12b00f34dc..5f32abfe653 100644 --- a/src/libstd/collections/lru_cache.rs +++ b/src/libstd/collections/lru_cache.rs @@ -227,7 +227,7 @@ impl fmt::Show for LruCache { } } -impl Container for LruCache { +impl Collection for LruCache { /// Return the number of key-value pairs in the cache. fn len(&self) -> uint { self.map.len() diff --git a/src/libstd/comm/sync.rs b/src/libstd/comm/sync.rs index 7fe505573b7..84ef6d0aa8f 100644 --- a/src/libstd/comm/sync.rs +++ b/src/libstd/comm/sync.rs @@ -33,7 +33,7 @@ /// of a synchronous channel. There are a few branches for the unbuffered case, /// but they're mostly just relevant to blocking senders. -use container::Container; +use collections::Collection; use iter::Iterator; use kinds::Send; use mem; diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 0d421760162..9450f7798ed 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -11,7 +11,7 @@ //! Buffering wrappers for I/O traits use cmp; -use container::Container; +use collections::Collection; use io::{Reader, Writer, Stream, Buffer, DEFAULT_BUF_SIZE, IoResult}; use iter::ExactSize; use ops::Drop; diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs index 45f783698cd..a06d5aa88d6 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/io/comm_adapters.rs @@ -10,7 +10,7 @@ use clone::Clone; use cmp; -use container::Container; +use collections::Collection; use comm::{Sender, Receiver}; use io; use option::{None, Option, Some}; diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index 29afd2b1d9b..d61518d4ee7 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -15,7 +15,7 @@ // FIXME: Not sure how this should be structured // FIXME: Iteration should probably be considered separately -use container::Container; +use collections::Collection; use iter::Iterator; use option::{Option, Some, None}; use result::{Ok, Err}; @@ -504,7 +504,7 @@ mod test { mod bench { extern crate test; - use container::Container; + use collections::Collection; use prelude::*; use self::test::Bencher; diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index 49e8d379236..5259200133a 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -51,7 +51,7 @@ fs::unlink(&path); use c_str::ToCStr; use clone::Clone; -use container::Container; +use collections::Collection; use io; use iter::Iterator; use kinds::Send; diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index 735966d812b..f0fbe4529b0 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -11,7 +11,7 @@ //! Readers and Writers for in-memory buffers use cmp::min; -use container::Container; +use collections::Collection; use option::None; use result::{Err, Ok}; use io; diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 7b655693395..6f3eec01e8e 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -214,7 +214,7 @@ responding to errors that may occur while attempting to read the numbers. #![deny(unused_must_use)] use char::Char; -use container::Container; +use collections::Collection; use fmt; use int; use iter::Iterator; diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index bdc4b6071fa..2c54bd895e9 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -15,7 +15,7 @@ #![allow(missing_doc)] -use container::Container; +use collections::Collection; use fmt; use from_str::FromStr; use iter::Iterator; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index bac4d26b4e4..d319d6bd03d 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -144,7 +144,7 @@ pub use core::cell; pub use core::char; pub use core::clone; #[cfg(not(test))] pub use core::cmp; -pub use core::container; +pub use core::collections; pub use core::default; pub use core::finally; pub use core::intrinsics; diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 48962ca59d8..5028987f44f 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -12,7 +12,7 @@ use char; use clone::Clone; -use container::Container; +use collections::Collection; use num::{NumCast, Zero, One, cast, Int}; use num::{Float, FPNaN, FPInfinite, ToPrimitive}; use num; diff --git a/src/libstd/os.rs b/src/libstd/os.rs index dd692d3fc01..90df18106f0 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -30,7 +30,7 @@ #![allow(non_snake_case_functions)] use clone::Clone; -use container::Container; +use collections::Collection; use fmt; use iter::Iterator; use libc::{c_void, c_int}; diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 681b19a2d1a..a101f043212 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -65,7 +65,7 @@ println!("path exists: {}", path.exists()); #![deny(deprecated_owned_vector)] -use container::Container; +use collections::Collection; use c_str::CString; use clone::Clone; use fmt; diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 9bb137edb82..011dfa6eeac 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -14,7 +14,7 @@ use ascii::AsciiCast; use c_str::{CString, ToCStr}; use clone::Clone; use cmp::{PartialEq, Eq}; -use container::Container; +use collections::Collection; use from_str::FromStr; use hash; use io::Writer; diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 766901fa04f..d52c63abe1b 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -13,7 +13,7 @@ #![allow(non_camel_case_types)] use char::Char; -use container::Container; +use collections::Collection; use from_str::from_str; use io::{IoResult, Writer}; use iter::Iterator; @@ -348,7 +348,7 @@ mod imp { #[cfg(not(target_os = "macos"))] fn print(w: &mut Writer, idx: int, addr: *libc::c_void) -> IoResult<()> { - use container::Container; + use collections::Collection; use iter::Iterator; use os; use path::GenericPath; diff --git a/src/libsyntax/owned_slice.rs b/src/libsyntax/owned_slice.rs index 28d63ea071a..016dd879dcd 100644 --- a/src/libsyntax/owned_slice.rs +++ b/src/libsyntax/owned_slice.rs @@ -121,7 +121,7 @@ impl PartialEq for OwnedSlice { impl Eq for OwnedSlice {} -impl Container for OwnedSlice { +impl Collection for OwnedSlice { fn len(&self) -> uint { self.len } } diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index 693407b854f..a3b2c23dfdf 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -23,7 +23,7 @@ enum SmallVectorRepr { Many(Vec ), } -impl Container for SmallVector { +impl Collection for SmallVector { fn len(&self) -> uint { match self.repr { Zero => 0, diff --git a/src/test/compile-fail/map-types.rs b/src/test/compile-fail/map-types.rs index 0c9a7cc8bde..61c26d4d8fd 100644 --- a/src/test/compile-fail/map-types.rs +++ b/src/test/compile-fail/map-types.rs @@ -18,6 +18,6 @@ fn main() { let x: Box> = box HashMap::new(); let x: Box> = x; let y: Box> = box x; - //~^ ERROR failed to find an implementation of trait core::container::Map - // for ~core::container::Map:Send + //~^ ERROR failed to find an implementation of trait core::collections::Map + // for ~core::collections::Map:Send } diff --git a/src/test/run-pass/class-impl-very-parameterized-trait.rs b/src/test/run-pass/class-impl-very-parameterized-trait.rs index 865984844c0..924625faa10 100644 --- a/src/test/run-pass/class-impl-very-parameterized-trait.rs +++ b/src/test/run-pass/class-impl-very-parameterized-trait.rs @@ -48,7 +48,7 @@ impl cat { } } -impl Container for cat { +impl Collection for cat { fn len(&self) -> uint { self.meows as uint } fn is_empty(&self) -> bool { self.meows == 0 } } diff --git a/src/test/run-pass/send_str_hashmap.rs b/src/test/run-pass/send_str_hashmap.rs index 750235ce6af..8b041ed3a3e 100644 --- a/src/test/run-pass/send_str_hashmap.rs +++ b/src/test/run-pass/send_str_hashmap.rs @@ -10,7 +10,7 @@ extern crate collections; -use std::container::{Map, MutableMap}; +use std::collections::{Map, MutableMap}; use std::str::{SendStr, Owned, Slice}; use std::collections::HashMap; use std::option::Some; diff --git a/src/test/run-pass/send_str_treemap.rs b/src/test/run-pass/send_str_treemap.rs index 5604093ea9c..68eca8f21a7 100644 --- a/src/test/run-pass/send_str_treemap.rs +++ b/src/test/run-pass/send_str_treemap.rs @@ -10,7 +10,7 @@ extern crate collections; -use std::container::{ Map, MutableMap}; +use std::collections::{ Map, MutableMap}; use std::str::{SendStr, Owned, Slice}; use std::to_str::ToStr; use self::collections::TreeMap; From da0703973af921626d7235131d14847b1aacffc2 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 6 Jun 2014 16:33:44 -0700 Subject: [PATCH 2/2] core: Move the collections traits to libcollections This commit moves Mutable, Map, MutableMap, Set, and MutableSet from `core::collections` to the `collections` crate at the top-level. Additionally, this removes the `deque` module and moves the `Deque` trait to only being available at the top-level of the collections crate. All functionality continues to be reexported through `std::collections`. [breaking-change] --- src/libcollections/bitv.rs | 2 + src/libcollections/btree.rs | 1 + src/libcollections/deque.rs | 31 +------ src/libcollections/dlist.rs | 6 +- src/libcollections/lib.rs | 123 +++++++++++++++++++++++++-- src/libcollections/priority_queue.rs | 1 + src/libcollections/ringbuf.rs | 6 +- src/libcollections/slice.rs | 7 +- src/libcollections/smallintmap.rs | 4 +- src/libcollections/str.rs | 1 + src/libcollections/string.rs | 2 + src/libcollections/treemap.rs | 4 +- src/libcollections/trie.rs | 4 + src/libcollections/vec.rs | 15 ++-- src/libcore/collections.rs | 86 +------------------ src/libstd/collections/hashmap.rs | 6 +- src/libstd/collections/lru_cache.rs | 3 +- src/libstd/collections/mod.rs | 6 +- src/libstd/lib.rs | 1 - src/libstd/path/posix.rs | 2 +- src/libstd/prelude.rs | 4 +- src/libstd/rand/os.rs | 2 +- src/libstd/rand/reader.rs | 2 +- src/libstd/rt/backtrace.rs | 2 +- src/test/compile-fail/map-types.rs | 4 +- 25 files changed, 171 insertions(+), 154 deletions(-) diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs index ac31fbbf9e4..42c81779770 100644 --- a/src/libcollections/bitv.rs +++ b/src/libcollections/bitv.rs @@ -20,6 +20,7 @@ use core::slice; use core::uint; use std::hash; +use {Collection, Mutable, Set, MutableSet}; use vec::Vec; #[deriving(Clone)] @@ -1008,6 +1009,7 @@ mod tests { use std::rand::Rng; use test::Bencher; + use {Set, Mutable, MutableSet}; use bitv::{Bitv, SmallBitv, BigBitv, BitvSet, from_bools, from_fn, from_bytes}; use bitv; diff --git a/src/libcollections/btree.rs b/src/libcollections/btree.rs index ebca0157da4..82abe69a639 100644 --- a/src/libcollections/btree.rs +++ b/src/libcollections/btree.rs @@ -24,6 +24,7 @@ use alloc::owned::Box; use core::fmt; use core::fmt::Show; +use Collection; use vec::Vec; #[allow(missing_doc)] diff --git a/src/libcollections/deque.rs b/src/libcollections/deque.rs index 5624c67f108..1faa9be99e3 100644 --- a/src/libcollections/deque.rs +++ b/src/libcollections/deque.rs @@ -10,41 +10,13 @@ //! Container traits for collections -use core::prelude::*; - -/// A double-ended sequence that allows querying, insertion and deletion at both ends. -pub trait Deque : Mutable { - /// Provide a reference to the front element, or None if the sequence is empty - fn front<'a>(&'a self) -> Option<&'a T>; - - /// Provide a mutable reference to the front element, or None if the sequence is empty - fn front_mut<'a>(&'a mut self) -> Option<&'a mut T>; - - /// Provide a reference to the back element, or None if the sequence is empty - fn back<'a>(&'a self) -> Option<&'a T>; - - /// Provide a mutable reference to the back element, or None if the sequence is empty - fn back_mut<'a>(&'a mut self) -> Option<&'a mut T>; - - /// Insert an element first in the sequence - fn push_front(&mut self, elt: T); - - /// Insert an element last in the sequence - fn push_back(&mut self, elt: T); - - /// Remove the last element and return it, or None if the sequence is empty - fn pop_back(&mut self) -> Option; - - /// Remove the first element and return it, or None if the sequence is empty - fn pop_front(&mut self) -> Option; -} - #[cfg(test)] pub mod bench { use std::prelude::*; use std::rand; use std::rand::Rng; use test::Bencher; + use MutableMap; pub fn insert_rand_n>(n: uint, map: &mut M, @@ -121,3 +93,4 @@ pub mod bench { }) } } + diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index f71cc7401c5..5a231245691 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -13,7 +13,7 @@ //! The DList allows pushing and popping elements at either end. //! //! DList implements the trait Deque. It should be imported with `use -//! collections::deque::Deque`. +//! collections::Deque`. // DList is constructed like a singly-linked list over the field `next`. // including the last link being None; each Node owns its `next` field. @@ -29,7 +29,7 @@ use core::iter; use core::mem; use core::ptr; -use deque::Deque; +use {Collection, Mutable, Deque}; /// A doubly-linked list. pub struct DList { @@ -629,7 +629,7 @@ mod tests { use test::Bencher; use test; - use deque::Deque; + use Deque; use super::{DList, Node, ListInsertion}; use vec::Vec; diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index c46ea84a765..602ecf39a83 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -32,9 +32,11 @@ extern crate alloc; #[cfg(test)] #[phase(syntax, link)] extern crate std; #[cfg(test)] #[phase(syntax, link)] extern crate log; +use core::prelude::*; + +pub use core::collections::Collection; pub use bitv::{Bitv, BitvSet}; pub use btree::BTree; -pub use deque::Deque; pub use dlist::DList; pub use enum_set::EnumSet; pub use priority_queue::PriorityQueue; @@ -47,7 +49,6 @@ mod macros; pub mod bitv; pub mod btree; -pub mod deque; pub mod dlist; pub mod enum_set; pub mod priority_queue; @@ -64,14 +65,122 @@ pub mod hash; // Internal unicode fiddly bits for the str module mod unicode; -// FIXME(#14008) should this actually exist, or should a method be added? -fn expect(a: core::option::Option, b: &str) -> T { - match a { - core::option::Some(a) => a, - core::option::None => fail!("{}", b), +mod deque; + +/// A trait to represent mutable containers +pub trait Mutable: Collection { + /// Clear the container, removing all values. + fn clear(&mut self); +} + +/// A map is a key-value store where values may be looked up by their keys. This +/// trait provides basic operations to operate on these stores. +pub trait Map: Collection { + /// Return a reference to the value corresponding to the key + fn find<'a>(&'a self, key: &K) -> Option<&'a V>; + + /// Return true if the map contains a value for the specified key + #[inline] + fn contains_key(&self, key: &K) -> bool { + self.find(key).is_some() } } +/// This trait provides basic operations to modify the contents of a map. +pub trait MutableMap: Map + Mutable { + /// Insert a key-value pair into the map. An existing value for a + /// key is replaced by the new value. Return true if the key did + /// not already exist in the map. + #[inline] + fn insert(&mut self, key: K, value: V) -> bool { + self.swap(key, value).is_none() + } + + /// Remove a key-value pair from the map. Return true if the key + /// was present in the map, otherwise false. + #[inline] + fn remove(&mut self, key: &K) -> bool { + self.pop(key).is_some() + } + + /// Insert a key-value pair from the map. If the key already had a value + /// present in the map, that value is returned. Otherwise None is returned. + fn swap(&mut self, k: K, v: V) -> Option; + + /// Removes a key from the map, returning the value at the key if the key + /// was previously in the map. + fn pop(&mut self, k: &K) -> Option; + + /// Return a mutable reference to the value corresponding to the key + fn find_mut<'a>(&'a mut self, key: &K) -> Option<&'a mut V>; +} + +/// A set is a group of objects which are each distinct from one another. This +/// trait represents actions which can be performed on sets to iterate over +/// them. +pub trait Set: Collection { + /// Return true if the set contains a value + fn contains(&self, value: &T) -> bool; + + /// Return true if the set has no elements in common with `other`. + /// This is equivalent to checking for an empty intersection. + fn is_disjoint(&self, other: &Self) -> bool; + + /// Return true if the set is a subset of another + fn is_subset(&self, other: &Self) -> bool; + + /// Return true if the set is a superset of another + fn is_superset(&self, other: &Self) -> bool { + other.is_subset(self) + } + + // FIXME #8154: Add difference, sym. difference, intersection and union iterators +} + +/// This trait represents actions which can be performed on sets to mutate +/// them. +pub trait MutableSet: Set + Mutable { + /// Add a value to the set. Return true if the value was not already + /// present in the set. + fn insert(&mut self, value: T) -> bool; + + /// Remove a value from the set. Return true if the value was + /// present in the set. + fn remove(&mut self, value: &T) -> bool; +} + +/// A double-ended sequence that allows querying, insertion and deletion at both +/// ends. +pub trait Deque : Mutable { + /// Provide a reference to the front element, or None if the sequence is + /// empty + fn front<'a>(&'a self) -> Option<&'a T>; + + /// Provide a mutable reference to the front element, or None if the + /// sequence is empty + fn front_mut<'a>(&'a mut self) -> Option<&'a mut T>; + + /// Provide a reference to the back element, or None if the sequence is + /// empty + fn back<'a>(&'a self) -> Option<&'a T>; + + /// Provide a mutable reference to the back element, or None if the sequence + /// is empty + fn back_mut<'a>(&'a mut self) -> Option<&'a mut T>; + + /// Insert an element first in the sequence + fn push_front(&mut self, elt: T); + + /// Insert an element last in the sequence + fn push_back(&mut self, elt: T); + + /// Remove the last element and return it, or None if the sequence is empty + fn pop_back(&mut self) -> Option; + + /// Remove the first element and return it, or None if the sequence is empty + fn pop_front(&mut self) -> Option; +} + // FIXME(#14344) this shouldn't be necessary #[doc(hidden)] pub fn fixme_14344_be_sure_to_link_to_collections() {} diff --git a/src/libcollections/priority_queue.rs b/src/libcollections/priority_queue.rs index f10c6f230ae..ea3e7d17471 100644 --- a/src/libcollections/priority_queue.rs +++ b/src/libcollections/priority_queue.rs @@ -17,6 +17,7 @@ use core::prelude::*; use core::mem::{zeroed, replace, swap}; use core::ptr; +use {Collection, Mutable}; use slice; use vec::Vec; diff --git a/src/libcollections/ringbuf.rs b/src/libcollections/ringbuf.rs index 5708dfaf915..addf73d67a8 100644 --- a/src/libcollections/ringbuf.rs +++ b/src/libcollections/ringbuf.rs @@ -11,7 +11,7 @@ //! A double-ended queue implemented as a circular buffer //! //! RingBuf implements the trait Deque. It should be imported with `use -//! collections::deque::Deque`. +//! collections::Deque`. use core::prelude::*; @@ -19,7 +19,7 @@ use core::cmp; use core::fmt; use core::iter::RandomAccessIterator; -use deque::Deque; +use {Deque, Collection, Mutable}; use vec::Vec; static INITIAL_CAPACITY: uint = 8u; // 2^3 @@ -415,7 +415,7 @@ mod tests { use test::Bencher; use test; - use deque::Deque; + use {Deque, Mutable}; use super::RingBuf; use vec::Vec; diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 4798218e3ff..1bc56368693 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -109,6 +109,8 @@ use core::mem::transmute; use core::mem; use core::ptr; use core::iter::{range_step, MultiplicativeIterator}; + +use Collection; use vec::Vec; pub use core::slice::{ref_slice, mut_ref_slice, Splits, Windows}; @@ -296,9 +298,9 @@ impl<'a, T: Clone> CloneableVector for &'a [T] { let len = self.len(); let data_size = len.checked_mul(&mem::size_of::()); - let data_size = ::expect(data_size, "overflow in to_owned()"); + let data_size = data_size.expect("overflow in to_owned()"); let size = mem::size_of::>().checked_add(&data_size); - let size = ::expect(size, "overflow in to_owned()"); + let size = size.expect("overflow in to_owned()"); unsafe { // this should pass the real required alignment @@ -865,6 +867,7 @@ mod tests { use std::rt; use slice::*; + use Mutable; use vec::Vec; fn square(n: uint) -> uint { n * n } diff --git a/src/libcollections/smallintmap.rs b/src/libcollections/smallintmap.rs index c61f518caa4..cc901864ab5 100644 --- a/src/libcollections/smallintmap.rs +++ b/src/libcollections/smallintmap.rs @@ -21,6 +21,7 @@ use core::fmt; use core::iter::{Enumerate, FilterMap}; use core::mem::replace; +use {Collection, Mutable, Map, MutableMap}; use {vec, slice}; use vec::Vec; @@ -123,7 +124,7 @@ impl SmallIntMap { } pub fn get<'a>(&'a self, key: &uint) -> &'a V { - ::expect(self.find(key), "key not present") + self.find(key).expect("key not present") } /// An iterator visiting all key-value pairs in ascending order by the keys. @@ -264,6 +265,7 @@ double_ended_iterator!(impl MutEntries -> (uint, &'a mut T), get_mut_ref) mod test_map { use std::prelude::*; + use {Map, MutableMap, Mutable}; use super::SmallIntMap; #[test] diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 102d9c3abde..49d8775dd9c 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -76,6 +76,7 @@ use core::cmp; use core::iter::AdditiveIterator; use core::mem; +use Collection; use hash; use string::String; use vec::Vec; diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 1c1d4b98592..76f53c9b257 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -18,6 +18,7 @@ use core::mem; use core::ptr; use core::raw::Slice; +use {Collection, Mutable}; use hash; use str; use str::{CharRange, StrAllocating}; @@ -356,6 +357,7 @@ mod tests { use std::prelude::*; use test::Bencher; + use Mutable; use str::{Str, StrSlice}; use super::String; diff --git a/src/libcollections/treemap.rs b/src/libcollections/treemap.rs index 8d472282a68..489fe60cebf 100644 --- a/src/libcollections/treemap.rs +++ b/src/libcollections/treemap.rs @@ -22,6 +22,7 @@ use core::iter; use core::mem::{replace, swap}; use core::ptr; +use {Collection, Mutable, Set, MutableSet, MutableMap, Map}; use vec::Vec; // This is implemented as an AA tree, which is a simplified variation of @@ -1006,6 +1007,7 @@ mod test_treemap { use std::rand::Rng; use std::rand; + use {Map, MutableMap, Mutable}; use super::{TreeMap, TreeNode}; #[test] @@ -1437,7 +1439,6 @@ mod test_treemap { #[cfg(test)] mod bench { - use std::prelude::*; use test::Bencher; use super::TreeMap; @@ -1500,6 +1501,7 @@ mod bench { mod test_set { use std::prelude::*; + use {Set, MutableSet, Mutable, MutableMap}; use super::{TreeMap, TreeSet}; #[test] diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs index 1c6b7ed9333..6e99d6054a5 100644 --- a/src/libcollections/trie.rs +++ b/src/libcollections/trie.rs @@ -17,6 +17,7 @@ use core::mem::zeroed; use core::mem; use core::uint; +use {Collection, Mutable, Map, MutableMap, Set, MutableSet}; use slice::{Items, MutItems}; use slice; @@ -645,6 +646,7 @@ mod test_map { use std::iter::range_step; use std::uint; + use {MutableMap, Map}; use super::{TrieMap, TrieNode, Internal, External, Nothing}; fn check_integrity(trie: &TrieNode) { @@ -923,6 +925,7 @@ mod bench_map { use std::rand::{weak_rng, Rng}; use test::Bencher; + use MutableMap; use super::TrieMap; #[bench] @@ -1031,6 +1034,7 @@ mod test_set { use std::prelude::*; use std::uint; + use {MutableSet, Set}; use super::TrieSet; #[test] diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 3d0182acc7e..dbef73efc47 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -24,6 +24,7 @@ use core::num; use core::ptr; use core::uint; +use {Collection, Mutable}; use slice::{MutableOrdVector, OwnedVector, MutableVectorAllocating}; use slice::{Items, MutItems}; @@ -91,8 +92,8 @@ impl Vec { } else if capacity == 0 { Vec::new() } else { - let size = ::expect(capacity.checked_mul(&mem::size_of::()), - "capacity overflow"); + let size = capacity.checked_mul(&mem::size_of::()) + .expect("capacity overflow"); let ptr = unsafe { allocate(size, mem::min_align_of::()) }; Vec { len: 0, cap: capacity, ptr: ptr as *mut T } } @@ -499,8 +500,8 @@ impl Vec { if mem::size_of::() == 0 { return } if capacity > self.cap { - let size = ::expect(capacity.checked_mul(&mem::size_of::()), - "capacity overflow"); + let size = capacity.checked_mul(&mem::size_of::()) + .expect("capacity overflow"); unsafe { self.ptr = alloc_or_realloc(self.ptr, size, self.cap * mem::size_of::()); @@ -579,7 +580,7 @@ impl Vec { pub fn push(&mut self, value: T) { if mem::size_of::() == 0 { // zero-size types consume no memory, so we can't rely on the address space running out - self.len = ::expect(self.len.checked_add(&1), "length overflow"); + self.len = self.len.checked_add(&1).expect("length overflow"); unsafe { mem::forget(value); } return } @@ -1526,9 +1527,9 @@ impl FromVec for ~[T] { fn from_vec(mut v: Vec) -> ~[T] { let len = v.len(); let data_size = len.checked_mul(&mem::size_of::()); - let data_size = ::expect(data_size, "overflow in from_vec()"); + let data_size = data_size.expect("overflow in from_vec()"); let size = mem::size_of::>().checked_add(&data_size); - let size = ::expect(size, "overflow in from_vec()"); + let size = size.expect("overflow in from_vec()"); // In a post-DST world, we can attempt to reuse the Vec allocation by calling // shrink_to_fit() on it. That may involve a reallocation+memcpy, but that's no diff --git a/src/libcore/collections.rs b/src/libcore/collections.rs index 8ebc7c2f7fe..0bb9289397a 100644 --- a/src/libcore/collections.rs +++ b/src/libcore/collections.rs @@ -8,9 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Traits for generic collections (including `Map` and `Set`) - -use option::Option; +//! Traits for generic collections /// A trait to represent the abstract idea of a container. The only concrete /// knowledge known is the number of elements contained within. @@ -24,85 +22,3 @@ pub trait Collection { self.len() == 0 } } - -/// A trait to represent mutable containers -pub trait Mutable: Collection { - /// Clear the container, removing all values. - fn clear(&mut self); -} - -/// A map is a key-value store where values may be looked up by their keys. This -/// trait provides basic operations to operate on these stores. -pub trait Map: Collection { - /// Return a reference to the value corresponding to the key - fn find<'a>(&'a self, key: &K) -> Option<&'a V>; - - /// Return true if the map contains a value for the specified key - #[inline] - fn contains_key(&self, key: &K) -> bool { - self.find(key).is_some() - } -} - -/// This trait provides basic operations to modify the contents of a map. -pub trait MutableMap: Map + Mutable { - /// Insert a key-value pair into the map. An existing value for a - /// key is replaced by the new value. Return true if the key did - /// not already exist in the map. - #[inline] - fn insert(&mut self, key: K, value: V) -> bool { - self.swap(key, value).is_none() - } - - /// Remove a key-value pair from the map. Return true if the key - /// was present in the map, otherwise false. - #[inline] - fn remove(&mut self, key: &K) -> bool { - self.pop(key).is_some() - } - - /// Insert a key-value pair from the map. If the key already had a value - /// present in the map, that value is returned. Otherwise None is returned. - fn swap(&mut self, k: K, v: V) -> Option; - - /// Removes a key from the map, returning the value at the key if the key - /// was previously in the map. - fn pop(&mut self, k: &K) -> Option; - - /// Return a mutable reference to the value corresponding to the key - fn find_mut<'a>(&'a mut self, key: &K) -> Option<&'a mut V>; -} - -/// A set is a group of objects which are each distinct from one another. This -/// trait represents actions which can be performed on sets to iterate over -/// them. -pub trait Set: Collection { - /// Return true if the set contains a value - fn contains(&self, value: &T) -> bool; - - /// Return true if the set has no elements in common with `other`. - /// This is equivalent to checking for an empty intersection. - fn is_disjoint(&self, other: &Self) -> bool; - - /// Return true if the set is a subset of another - fn is_subset(&self, other: &Self) -> bool; - - /// Return true if the set is a superset of another - fn is_superset(&self, other: &Self) -> bool { - other.is_subset(self) - } - - // FIXME #8154: Add difference, sym. difference, intersection and union iterators -} - -/// This trait represents actions which can be performed on sets to mutate -/// them. -pub trait MutableSet: Set + Mutable { - /// Add a value to the set. Return true if the value was not already - /// present in the set. - fn insert(&mut self, value: T) -> bool; - - /// Remove a value from the set. Return true if the value was - /// present in the set. - fn remove(&mut self, value: &T) -> bool; -} diff --git a/src/libstd/collections/hashmap.rs b/src/libstd/collections/hashmap.rs index 1f3c34600bd..a780b63bfd0 100644 --- a/src/libstd/collections/hashmap.rs +++ b/src/libstd/collections/hashmap.rs @@ -12,7 +12,7 @@ use clone::Clone; use cmp::{max, Eq, Equiv, PartialEq}; -use container::{Container, Mutable, Set, MutableSet, Map, MutableMap}; +use collections::{Collection, Mutable, Set, MutableSet, Map, MutableMap}; use default::Default; use fmt::Show; use fmt; @@ -930,7 +930,7 @@ impl, V, S, H: Hasher> HashMap { } } -impl, V, S, H: Hasher> Container for HashMap { +impl, V, S, H: Hasher> Collection for HashMap { /// Return the number of elements in the map fn len(&self) -> uint { self.table.size() } } @@ -2160,7 +2160,7 @@ mod test_set { use super::HashSet; use slice::ImmutableEqVector; - use std::collections::Collection; + use collections::Collection; #[test] fn test_disjoint() { diff --git a/src/libstd/collections/lru_cache.rs b/src/libstd/collections/lru_cache.rs index 5f32abfe653..72d96804d6d 100644 --- a/src/libstd/collections/lru_cache.rs +++ b/src/libstd/collections/lru_cache.rs @@ -38,8 +38,7 @@ //! ``` use cmp::{PartialEq, Eq}; -use collections::HashMap; -use container::{Container, Mutable, MutableMap}; +use collections::{HashMap, Collection, Mutable, MutableMap}; use fmt; use hash::Hash; use iter::{range, Iterator}; diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs index 16a6a35d9d5..9e5288f9541 100644 --- a/src/libstd/collections/mod.rs +++ b/src/libstd/collections/mod.rs @@ -12,10 +12,12 @@ * Collection types. */ -pub use core_collections::{Bitv, BitvSet, BTree, Deque, DList, EnumSet}; +pub use core_collections::{Collection, Mutable, Map, MutableMap}; +pub use core_collections::{Set, MutableSet, Deque}; +pub use core_collections::{Bitv, BitvSet, BTree, DList, EnumSet}; pub use core_collections::{PriorityQueue, RingBuf, SmallIntMap}; pub use core_collections::{TreeMap, TreeSet, TrieMap, TrieSet}; -pub use core_collections::{bitv, btree, deque, dlist, enum_set}; +pub use core_collections::{bitv, btree, dlist, enum_set}; pub use core_collections::{priority_queue, ringbuf, smallintmap, treemap, trie}; pub use self::hashmap::{HashMap, HashSet}; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index d319d6bd03d..fbdbc13e1b4 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -144,7 +144,6 @@ pub use core::cell; pub use core::char; pub use core::clone; #[cfg(not(test))] pub use core::cmp; -pub use core::collections; pub use core::default; pub use core::finally; pub use core::intrinsics; diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 8dfb64194e7..171535edbeb 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -13,7 +13,7 @@ use c_str::{CString, ToCStr}; use clone::Clone; use cmp::{PartialEq, Eq}; -use container::Container; +use collections::Collection; use from_str::FromStr; use hash; use io::Writer; diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 54dcbd1812f..485c2140a8d 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -60,8 +60,8 @@ #[doc(no_inline)] pub use clone::Clone; #[doc(no_inline)] pub use cmp::{PartialEq, PartialOrd, Eq, Ord}; #[doc(no_inline)] pub use cmp::{Ordering, Less, Equal, Greater, Equiv}; -#[doc(no_inline)] pub use container::{Container, Mutable, Map, MutableMap}; -#[doc(no_inline)] pub use container::{Set, MutableSet}; +#[doc(no_inline)] pub use collections::{Collection, Mutable, Map, MutableMap}; +#[doc(no_inline)] pub use collections::{Set, MutableSet}; #[doc(no_inline)] pub use iter::{FromIterator, Extendable, ExactSize}; #[doc(no_inline)] pub use iter::{Iterator, DoubleEndedIterator}; #[doc(no_inline)] pub use iter::{RandomAccessIterator, CloneableIterator}; diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index 284d41d3208..2654b7a1acc 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -62,7 +62,7 @@ mod imp { mod imp { extern crate libc; - use container::Container; + use core_collections::Collection; use io::{IoResult, IoError}; use mem; use ops::Drop; diff --git a/src/libstd/rand/reader.rs b/src/libstd/rand/reader.rs index 170884073f3..8655d1e47d5 100644 --- a/src/libstd/rand/reader.rs +++ b/src/libstd/rand/reader.rs @@ -10,7 +10,7 @@ //! A wrapper around any Reader to treat it as an RNG. -use container::Container; +use collections::Collection; use io::Reader; use rand::Rng; use result::{Ok, Err}; diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index d52c63abe1b..83fc95267af 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -602,7 +602,7 @@ mod imp { #[allow(dead_code, uppercase_variables)] mod imp { use c_str::CString; - use container::Container; + use core_collections::Collection; use intrinsics; use io::{IoResult, Writer}; use libc; diff --git a/src/test/compile-fail/map-types.rs b/src/test/compile-fail/map-types.rs index 61c26d4d8fd..bb5f020e78c 100644 --- a/src/test/compile-fail/map-types.rs +++ b/src/test/compile-fail/map-types.rs @@ -18,6 +18,6 @@ fn main() { let x: Box> = box HashMap::new(); let x: Box> = x; let y: Box> = box x; - //~^ ERROR failed to find an implementation of trait core::collections::Map - // for ~core::collections::Map:Send + //~^ ERROR failed to find an implementation of trait collections::Map + // for ~collections::Map:Send }