diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-06-09 14:39:23 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-06-17 09:06:59 -0700 |
| commit | d444d0c357e85c90e73585520e2da74304c7265a (patch) | |
| tree | b64c15147beeccf6cd62eb019d76b16dc5260e22 /src/libcollections/enum_set.rs | |
| parent | c44f5399e4dd2f9d55e107d365d6fe98f6491dc9 (diff) | |
| download | rust-d444d0c357e85c90e73585520e2da74304c7265a.tar.gz rust-d444d0c357e85c90e73585520e2da74304c7265a.zip | |
collections: Split the `collections` feature
This commit also deprecates the `as_string` and `as_slice` free functions in the `string` and `vec` modules.
Diffstat (limited to 'src/libcollections/enum_set.rs')
| -rw-r--r-- | src/libcollections/enum_set.rs | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index ad90f9f1caa..e90e6c065a2 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -13,21 +13,26 @@ //! This module defines a container which uses an efficient bit mask //! representation to hold C-like enum variants. +#![unstable(feature = "enumset", + reason = "matches collection reform specification, \ + waiting for dust to settle")] + use core::prelude::*; use core::marker; use core::fmt; use core::iter::{FromIterator}; use core::ops::{Sub, BitOr, BitAnd, BitXor}; -// FIXME(contentions): implement union family of methods? (general design may be wrong here) +// FIXME(contentions): implement union family of methods? (general design may be +// wrong here) -#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)] /// A specialized set implementation to use enum types. /// -/// It is a logic error for an item to be modified in such a way that the transformation of the -/// item to or from a `usize`, as determined by the `CLike` trait, changes while the item is in the -/// set. This is normally only possible through `Cell`, `RefCell`, global state, I/O, or unsafe -/// code. +/// It is a logic error for an item to be modified in such a way that the +/// transformation of the item to or from a `usize`, as determined by the +/// `CLike` trait, changes while the item is in the set. This is normally only +/// possible through `Cell`, `RefCell`, global state, I/O, or unsafe code. +#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct EnumSet<E> { // We must maintain the invariant that no bits are set // for which no variant exists @@ -93,22 +98,16 @@ fn bit<E:CLike>(e: &E) -> usize { impl<E:CLike> EnumSet<E> { /// Returns an empty `EnumSet`. - #[unstable(feature = "collections", - reason = "matches collection reform specification, waiting for dust to settle")] pub fn new() -> EnumSet<E> { EnumSet {bits: 0, marker: marker::PhantomData} } /// Returns the number of elements in the given `EnumSet`. - #[unstable(feature = "collections", - reason = "matches collection reform specification, waiting for dust to settle")] pub fn len(&self) -> usize { self.bits.count_ones() as usize } /// Returns true if the `EnumSet` is empty. - #[unstable(feature = "collections", - reason = "matches collection reform specification, waiting for dust to settle")] pub fn is_empty(&self) -> bool { self.bits == 0 } @@ -118,22 +117,16 @@ impl<E:CLike> EnumSet<E> { } /// Returns `false` if the `EnumSet` contains any enum of the given `EnumSet`. - #[unstable(feature = "collections", - reason = "matches collection reform specification, waiting for dust to settle")] pub fn is_disjoint(&self, other: &EnumSet<E>) -> bool { (self.bits & other.bits) == 0 } /// Returns `true` if a given `EnumSet` is included in this `EnumSet`. - #[unstable(feature = "collections", - reason = "matches collection reform specification, waiting for dust to settle")] pub fn is_superset(&self, other: &EnumSet<E>) -> bool { (self.bits & other.bits) == other.bits } /// Returns `true` if this `EnumSet` is included in the given `EnumSet`. - #[unstable(feature = "collections", - reason = "matches collection reform specification, waiting for dust to settle")] pub fn is_subset(&self, other: &EnumSet<E>) -> bool { other.is_superset(self) } @@ -151,8 +144,6 @@ impl<E:CLike> EnumSet<E> { } /// Adds an enum to the `EnumSet`, and returns `true` if it wasn't there before - #[unstable(feature = "collections", - reason = "matches collection reform specification, waiting for dust to settle")] pub fn insert(&mut self, e: E) -> bool { let result = !self.contains(&e); self.bits |= bit(&e); @@ -160,8 +151,6 @@ impl<E:CLike> EnumSet<E> { } /// Removes an enum from the EnumSet - #[unstable(feature = "collections", - reason = "matches collection reform specification, waiting for dust to settle")] pub fn remove(&mut self, e: &E) -> bool { let result = self.contains(e); self.bits &= !bit(e); @@ -169,15 +158,11 @@ impl<E:CLike> EnumSet<E> { } /// Returns `true` if an `EnumSet` contains a given enum. - #[unstable(feature = "collections", - reason = "matches collection reform specification, waiting for dust to settle")] pub fn contains(&self, e: &E) -> bool { (self.bits & bit(e)) != 0 } /// Returns an iterator over an `EnumSet`. - #[unstable(feature = "collections", - reason = "matches collection reform specification, waiting for dust to settle")] pub fn iter(&self) -> Iter<E> { Iter::new(self.bits) } |
