@@ -591,26 +591,41 @@ not_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
591591///
592592/// # Examples
593593///
594- /// A trivial implementation of `BitAnd`. When `Foo & Foo` happens, it ends up
595- /// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!` .
594+ /// In this example, the `BitAnd` trait is implemented for a `BooleanVector`
595+ /// struct .
596596///
597597/// ```
598598/// use std::ops::BitAnd;
599599///
600- /// struct Foo;
601- ///
602- /// impl BitAnd for Foo {
603- /// type Output = Foo;
604- ///
605- /// fn bitand(self, _rhs: Foo) -> Foo {
606- /// println!("Bitwise And-ing!");
607- /// self
600+ /// #[derive(Debug)]
601+ /// struct BooleanVector {
602+ /// value: Vec<bool>,
603+ /// };
604+ ///
605+ /// impl BitAnd for BooleanVector {
606+ /// type Output = Self;
607+ ///
608+ /// fn bitand(self, rhs: Self) -> Self {
609+ /// BooleanVector {
610+ /// value: self.value
611+ /// .iter()
612+ /// .zip(rhs.value.iter())
613+ /// .map(|(x, y)| *x && *y)
614+ /// .collect(),
615+ /// }
608616/// }
609617/// }
610618///
611- /// fn main() {
612- /// Foo & Foo;
619+ /// impl PartialEq for BooleanVector {
620+ /// fn eq(&self, other: &Self) -> bool {
621+ /// self.value == other.value
622+ /// }
613623/// }
624+ ///
625+ /// let bv1 = BooleanVector { value: vec![true, true, false, false] };
626+ /// let bv2 = BooleanVector { value: vec![true, false, true, false] };
627+ /// let expected = BooleanVector { value: vec![true, false, false, false] };
628+ /// assert_eq!(bv1 & bv2, expected);
614629/// ```
615630#[ lang = "bitand" ]
616631#[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments