pub struct Search {
pub matches: Vec<usize>,
pub pattern: String,
pub start_idx: Option<usize>,
/* private fields */
}Fields§
§matches: Vec<usize>§pattern: String§start_idx: Option<usize>Implementations§
Source§impl Search
impl Search
Sourcepub fn search(
&mut self,
list: &[Utf32String],
direction: Direction,
) -> Option<usize>
pub fn search( &mut self, list: &[Utf32String], direction: Direction, ) -> Option<usize>
Searches for pattern in the list and the given direction. Returns the index of the first
match.
§Examples
let mut search = Search::default();
search.pattern = String::from("ap");
let list = ["apple", "pineapple", "clementine"]
.iter()
.map(|s| Utf32String::from(*s))
.collect::<Vec<_>>();
let idx = search.search(&list, Direction::Forward);
assert_eq!(idx, Some(0));
let idx = search.search(&list, Direction::Backward);
assert_eq!(idx, Some(1));
search.start_idx = Some(0);
let idx = search.search(&list, Direction::Forward);
assert_eq!(idx, Some(1));Sourcepub fn next_match(&mut self) -> Option<&usize>
pub fn next_match(&mut self) -> Option<&usize>
Returns the index of the first match after start_idx or the first match if it is None.
Sourcepub fn previous_match(&mut self) -> Option<&usize>
pub fn previous_match(&mut self) -> Option<&usize>
Returns the index of the first match before start_idx or the last match if it is None.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Search
impl RefUnwindSafe for Search
impl Send for Search
impl Sync for Search
impl Unpin for Search
impl UnsafeUnpin for Search
impl UnwindSafe for Search
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more