[][src]Struct bitap::Pattern

pub struct Pattern { /* fields omitted */ }

A compiled pattern string that can be used to search text.

Methods

impl Pattern[src]

pub fn new(pattern: &str) -> Result<Pattern, &'static str>[src]

Compiles and returns a new pattern from the passed string. Will fail if the passed pattern is empty or longer than the system word size.

pub fn len(&self) -> usize[src]

Returns the length of the pattern in characters.

pub fn find<'a>(&'a self, text: &'a str) -> impl Iterator<Item = usize> + 'a[src]

Returns an iterator of character indexes where the pattern can be found within the passed text.

Unlike str::matches, it will find and return overlapping matches.

use bitap::{Pattern};
let pattern = Pattern::new("world")?;
assert_eq!(pattern.find("hello world").next(), Some(6));

pub fn lev<'a>(
    &'a self,
    text: &'a str,
    max_distance: usize
) -> impl Iterator<Item = Match> + 'a
[src]

Returns an iterator of matches where the pattern matched the passed text within a levenshtein distance of max_distance.

use bitap::{Pattern,Match};
let pattern = Pattern::new("wxrld")?;
let m = pattern.lev("hello world", 1).next();
assert_eq!(m, Some(Match{ distance: 1, end: 10 }));

pub fn osa<'a>(
    &'a self,
    text: &'a str,
    max_distance: usize
) -> impl Iterator<Item = Match> + 'a
[src]

Returns an iterator of matches where the pattern matched the passed text within an optimal string alignment distance of max_distance.

use bitap::{Pattern,Match};
let pattern = Pattern::new("wrold")?;
let m = pattern.osa("hello world", 1).next();
assert_eq!(m, Some(Match{ distance: 1, end: 10 }));

pub fn lev_static<'a>(
    &'a self,
    text: &'a str,
    max_distance: StaticMaxDistance
) -> impl Iterator<Item = Match> + 'a
[src]

The same as lev, but optimized for a max_distance of 1-2.

pub fn osa_static<'a>(
    &'a self,
    text: &'a str,
    max_distance: StaticMaxDistance
) -> impl Iterator<Item = Match> + 'a
[src]

The same as osa, but optimized for a max_distance of 1-2.

Auto Trait Implementations

impl Send for Pattern

impl Unpin for Pattern

impl Sync for Pattern

impl UnwindSafe for Pattern

impl RefUnwindSafe for Pattern

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]