//! representation to hold C-like enum variants.
use core::prelude::*;
+use core::marker;
use core::fmt;
use core::num::Int;
use core::iter::{FromIterator, IntoIterator};
pub struct EnumSet<E> {
// We must maintain the invariant that no bits are set
// for which no variant exists
- bits: usize
+ bits: usize,
+ marker: marker::PhantomData<E>,
}
impl<E> Copy for EnumSet<E> {}
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub fn new() -> EnumSet<E> {
- EnumSet {bits: 0}
+ EnumSet {bits: 0, marker: marker::PhantomData}
}
/// Returns the number of elements in the given `EnumSet`.
/// Returns the union of both `EnumSets`.
pub fn union(&self, e: EnumSet<E>) -> EnumSet<E> {
- EnumSet {bits: self.bits | e.bits}
+ EnumSet {bits: self.bits | e.bits,
+ marker: marker::PhantomData}
}
/// Returns the intersection of both `EnumSets`.
pub fn intersection(&self, e: EnumSet<E>) -> EnumSet<E> {
- EnumSet {bits: self.bits & e.bits}
+ EnumSet {bits: self.bits & e.bits,
+ marker: marker::PhantomData}
}
/// Adds an enum to the `EnumSet`, and returns `true` if it wasn't there before
type Output = EnumSet<E>;
fn sub(self, e: EnumSet<E>) -> EnumSet<E> {
- EnumSet {bits: self.bits & !e.bits}
+ EnumSet {bits: self.bits & !e.bits, marker: marker::PhantomData}
}
}
type Output = EnumSet<E>;
fn bitor(self, e: EnumSet<E>) -> EnumSet<E> {
- EnumSet {bits: self.bits | e.bits}
+ EnumSet {bits: self.bits | e.bits, marker: marker::PhantomData}
}
}
type Output = EnumSet<E>;
fn bitand(self, e: EnumSet<E>) -> EnumSet<E> {
- EnumSet {bits: self.bits & e.bits}
+ EnumSet {bits: self.bits & e.bits, marker: marker::PhantomData}
}
}
type Output = EnumSet<E>;
fn bitxor(self, e: EnumSet<E>) -> EnumSet<E> {
- EnumSet {bits: self.bits ^ e.bits}
+ EnumSet {bits: self.bits ^ e.bits, marker: marker::PhantomData}
}
}
pub struct Iter<E> {
index: usize,
bits: usize,
+ marker: marker::PhantomData<E>,
}
// FIXME(#19839) Remove in favor of `#[derive(Clone)]`
Iter {
index: self.index,
bits: self.bits,
+ marker: marker::PhantomData,
}
}
}
impl<E:CLike> Iter<E> {
fn new(bits: usize) -> Iter<E> {
- Iter { index: 0, bits: bits }
+ Iter { index: 0, bits: bits, marker: marker::PhantomData }
}
}