Skip to content

Commit bb8ef79

Browse files
ctrlcctrlvGeal
authored andcommitted
impl<'a> FindToken<char> for &'a [char]
Close #1282.
1 parent dae689e commit bb8ef79

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/traits.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,18 @@ impl<'a> FindToken<char> for &'a str {
914914
}
915915
}
916916

917+
impl<'a> FindToken<char> for &'a [char] {
918+
fn find_token(&self, token: char) -> bool {
919+
self.iter().any(|i| *i == token)
920+
}
921+
}
922+
923+
impl<'a, 'b> FindToken<&'a char> for &'b [char] {
924+
fn find_token(&self, token: &char) -> bool {
925+
self.find_token(*token)
926+
}
927+
}
928+
917929
/// Look for a substring in self
918930
pub trait FindSubstring<T> {
919931
/// Returns the byte position of the substring if it is found

tests/issues.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,11 @@ fn issue_1231_bits_expect_fn_closure() {
206206
}
207207
assert_eq!(example(&[0xff]), Ok((&b""[..], (1, 1))));
208208
}
209+
210+
#[test]
211+
fn issue_1282_findtoken_char() {
212+
use nom::character::complete::one_of;
213+
use nom::error::Error;
214+
let parser = one_of::<_, _, Error<_>>(['a', 'b', 'c'].as_slice());
215+
assert_eq!(parser("aaa"), Ok(("aa", 'a')));
216+
}

0 commit comments

Comments
 (0)