Pattern

Trait Pattern 

Source
pub trait Pattern: Sealed {
    type Output;
    type Owned: Pattern;
    type FindAllImpl<A>: Iterator<Item = (Range<usize>, Self::Output)> + FusedIterator
       where A: Accessor;
    type RFindAllImpl<A>: Iterator<Item = (Range<usize>, Self::Output)> + FusedIterator
       where A: Accessor;
}
Expand description

Trait for types that can be matched on.

This sealed trait provides ad-hoc polymorphism for methods such as find which involve searching a rope for a substring, Similarly to the standard library trait std::str::pattern::Pattern, the type of Pattern provided determines the match condition:

Pattern typeMatch condition
&stris substring
String, &Stringis substring
Rope, &Ropeis substring
charis contained in rope
&[char], Vec<char>any char in slice is contained in rope
F: Fn(char) -> boolF returns true for a char in rope

The type of pattern likewise determines the complexity of the search. In the following table, N represents the length of the needle, or when the needle is a predicate, its execution time. H represents the length of the hasystack. Note most search algorithms allocate O(N) temprorary storage regardless of whether the needle is borrowed or owned.

Pattern typeTime complexitySpace complexity
&strO(N + H log H)O(N)
String, &StringO(N + H log H)O(N)
Rope, &RopeO(N + H log H)O(N)
charO(H log H)O(1)
&[char]O(N log N + H log H log N)O(N)
Vec<char>O(N log N + H log H log N)O(1)
F: Fn(char) -> boolO(NH log H)O(1)

All of this trait’s methods are #[doc(hidden)] and are excluded from this crate’s semantic versioning contract.

Required Associated Types§

Source

type Output

For some patterns, this type is returned along with the match range to indicate what was matched. Patterns that match on character predicates or sets of characters have an output of char. Patterns that match on a single string just output ().

Source

type Owned: Pattern

The equivalent owned version of this pattern. This type appears in the signature of FindAll::into_owning but is otherwise uninteresting for consumers of this crate.

Source

type FindAllImpl<A>: Iterator<Item = (Range<usize>, Self::Output)> + FusedIterator where A: Accessor

The type which implements forward search for this pattern. This type in bounds on iterator implementations on FindAll but is otherwise uninteresting for consumers of this crate.

Source

type RFindAllImpl<A>: Iterator<Item = (Range<usize>, Self::Output)> + FusedIterator where A: Accessor

The type which implements reverse search for this pattern. This type in bounds on iterator implementations on RFindAll but is otherwise uninteresting for consumers of this crate.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Pattern for char

Source§

type Output = char

Source§

type Owned = char

Source§

type FindAllImpl<A> = FindChar<A, false> where A: Accessor

Source§

type RFindAllImpl<A> = FindChar<A, true> where A: Accessor

Source§

impl Pattern for String

Source§

type Output = ()

Source§

type Owned = String

Source§

type FindAllImpl<A> = FindStr<'static, A> where A: Accessor

Source§

type RFindAllImpl<A> = RFindStr<'static, A> where A: Accessor

Source§

impl Pattern for Vec<char>

Source§

type Output = char

Source§

type Owned = Vec<char>

Source§

type FindAllImpl<A> = FindChars<A, false> where A: Accessor

Source§

type RFindAllImpl<A> = FindChars<A, true> where A: Accessor

Source§

impl<'a> Pattern for &'a Vec<char>

Source§

type Output = char

Source§

type Owned = Vec<char>

Source§

type FindAllImpl<A> = FindChars<A, false> where A: Accessor

Source§

type RFindAllImpl<A> = FindChars<A, true> where A: Accessor

Source§

impl<'a> Pattern for &'a [char]

Source§

type Output = char

Source§

type Owned = Vec<char>

Source§

type FindAllImpl<A> = FindChars<A, false> where A: Accessor

Source§

type RFindAllImpl<A> = FindChars<A, true> where A: Accessor

Source§

impl<'n> Pattern for &'n str

Source§

type Output = ()

Source§

type Owned = String

Source§

type FindAllImpl<A> = FindStr<'n, A> where A: Accessor

Source§

type RFindAllImpl<A> = RFindStr<'n, A> where A: Accessor

Source§

impl<'n> Pattern for &'n String

Source§

type Output = ()

Source§

type Owned = String

Source§

type FindAllImpl<A> = FindStr<'n, A> where A: Accessor

Source§

type RFindAllImpl<A> = RFindStr<'n, A> where A: Accessor

Implementors§

Source§

impl Pattern for Rope

Source§

type Output = ()

Source§

type Owned = Rope

Source§

type FindAllImpl<A> = FindStr<'static, A> where A: Accessor

Source§

type RFindAllImpl<A> = RFindStr<'static, A> where A: Accessor

Source§

impl<'n> Pattern for &'n Rope

Source§

type Output = ()

Source§

type Owned = Rope

Source§

type FindAllImpl<A> = FindStr<'static, A> where A: Accessor

Source§

type RFindAllImpl<A> = RFindStr<'static, A> where A: Accessor

Source§

impl<F> Pattern for F
where F: Fn(char) -> bool,

Source§

type Output = char

Source§

type Owned = F

Source§

type FindAllImpl<A> = FindPred<A, F, false> where A: Accessor

Source§

type RFindAllImpl<A> = FindPred<A, F, true> where A: Accessor