Skip to content

Commit

Permalink
implement ops::Not for AsciiSet
Browse files Browse the repository at this point in the history
  • Loading branch information
joshka committed Sep 19, 2024
1 parent 360b17e commit b9f44f6
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions percent_encoding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ impl ops::Add for AsciiSet {
}
}

impl ops::Not for AsciiSet {
type Output = Self;

fn not(self) -> Self {
let mask = self.mask.map(|chunk| !chunk);
AsciiSet { mask }
}
}

/// The set of 0x00 to 0x1F (C0 controls), and 0x7F (DEL).
///
/// Note that this includes the newline and tab characters, but not the space 0x20.
Expand Down Expand Up @@ -508,4 +517,12 @@ mod tests {
let expected = AsciiSet::EMPTY.add(b'A').add(b'B');
assert_eq!(left + right, expected);
}

#[test]
fn not() {
let set = AsciiSet::EMPTY.add(b'A').add(b'B');
let not_set = !set;
assert!(!not_set.contains(b'A'));
assert!(not_set.contains(b'C'));
}
}

0 comments on commit b9f44f6

Please sign in to comment.