diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index cd01c008fe1b..d4c05e4b7d39 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -409,6 +409,8 @@ impl Default for BTreeSet { } #[unstable = "matches collection reform specification, waiting for dust to settle"] +// NOTE(stage0): Remove impl after a snapshot +#[cfg(stage0)] impl Sub,BTreeSet> for BTreeSet { /// Returns the difference of `self` and `rhs` as a new `BTreeSet`. /// @@ -430,6 +432,30 @@ impl Sub,BTreeSet> for BTreeSet { } #[unstable = "matches collection reform specification, waiting for dust to settle"] +#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot +impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet, BTreeSet> for &'a BTreeSet { + /// Returns the difference of `self` and `rhs` as a new `BTreeSet`. + /// + /// # Examples + /// + /// ``` + /// use std::collections::BTreeSet; + /// + /// let a: BTreeSet = vec![1, 2, 3].into_iter().collect(); + /// let b: BTreeSet = vec![3, 4, 5].into_iter().collect(); + /// + /// let result: BTreeSet = &a - &b; + /// let result_vec: Vec = result.into_iter().collect(); + /// assert_eq!(result_vec, vec![1, 2]); + /// ``` + fn sub(self, rhs: &BTreeSet) -> BTreeSet { + self.difference(rhs).cloned().collect() + } +} + +#[unstable = "matches collection reform specification, waiting for dust to settle"] +// NOTE(stage0): Remove impl after a snapshot +#[cfg(stage0)] impl BitXor,BTreeSet> for BTreeSet { /// Returns the symmetric difference of `self` and `rhs` as a new `BTreeSet`. /// @@ -451,6 +477,30 @@ impl BitXor,BTreeSet> for BTreeSet { } #[unstable = "matches collection reform specification, waiting for dust to settle"] +#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot +impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet, BTreeSet> for &'a BTreeSet { + /// Returns the symmetric difference of `self` and `rhs` as a new `BTreeSet`. + /// + /// # Examples + /// + /// ``` + /// use std::collections::BTreeSet; + /// + /// let a: BTreeSet = vec![1, 2, 3].into_iter().collect(); + /// let b: BTreeSet = vec![2, 3, 4].into_iter().collect(); + /// + /// let result: BTreeSet = &a ^ &b; + /// let result_vec: Vec = result.into_iter().collect(); + /// assert_eq!(result_vec, vec![1, 4]); + /// ``` + fn bitxor(self, rhs: &BTreeSet) -> BTreeSet { + self.symmetric_difference(rhs).cloned().collect() + } +} + +#[unstable = "matches collection reform specification, waiting for dust to settle"] +// NOTE(stage0): Remove impl after a snapshot +#[cfg(stage0)] impl BitAnd,BTreeSet> for BTreeSet { /// Returns the intersection of `self` and `rhs` as a new `BTreeSet`. /// @@ -472,6 +522,30 @@ impl BitAnd,BTreeSet> for BTreeSet { } #[unstable = "matches collection reform specification, waiting for dust to settle"] +#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot +impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet, BTreeSet> for &'a BTreeSet { + /// Returns the intersection of `self` and `rhs` as a new `BTreeSet`. + /// + /// # Examples + /// + /// ``` + /// use std::collections::BTreeSet; + /// + /// let a: BTreeSet = vec![1, 2, 3].into_iter().collect(); + /// let b: BTreeSet = vec![2, 3, 4].into_iter().collect(); + /// + /// let result: BTreeSet = &a & &b; + /// let result_vec: Vec = result.into_iter().collect(); + /// assert_eq!(result_vec, vec![2, 3]); + /// ``` + fn bitand(self, rhs: &BTreeSet) -> BTreeSet { + self.intersection(rhs).cloned().collect() + } +} + +#[unstable = "matches collection reform specification, waiting for dust to settle"] +// NOTE(stage0): Remove impl after a snapshot +#[cfg(stage0)] impl BitOr,BTreeSet> for BTreeSet { /// Returns the union of `self` and `rhs` as a new `BTreeSet`. /// @@ -492,6 +566,28 @@ impl BitOr,BTreeSet> for BTreeSet { } } +#[unstable = "matches collection reform specification, waiting for dust to settle"] +#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot +impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet, BTreeSet> for &'a BTreeSet { + /// Returns the union of `self` and `rhs` as a new `BTreeSet`. + /// + /// # Examples + /// + /// ``` + /// use std::collections::BTreeSet; + /// + /// let a: BTreeSet = vec![1, 2, 3].into_iter().collect(); + /// let b: BTreeSet = vec![3, 4, 5].into_iter().collect(); + /// + /// let result: BTreeSet = &a | &b; + /// let result_vec: Vec = result.into_iter().collect(); + /// assert_eq!(result_vec, vec![1, 2, 3, 4, 5]); + /// ``` + fn bitor(self, rhs: &BTreeSet) -> BTreeSet { + self.union(rhs).cloned().collect() + } +} + impl Show for BTreeSet { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "{{"));