Pattern

Trait Pattern 

Source
pub trait Pattern {
    type Err: Debug;

    // Required method
    fn matches(&mut self, c: char, s: &str) -> Result<bool, Self::Err>;

    // Provided methods
    fn len(&self) -> NonZeroUsize { ... }
    fn sep(&self) -> Sep { ... }
}
Expand description

A pattern for use in slice, split and trim functions.

Required Associated Types§

Required Methods§

Source

fn matches(&mut self, c: char, s: &str) -> Result<bool, Self::Err>

Try matching a char in a pattern

§Arguments
  • c - The current char, guaranteed to be the first char in s
  • s - The current &str, a substring of some length after c

In slice or split: match until the first true result

In trim_by: match until the first false result

len() is a suggestion for s.len(). However s is not guaranteed to have the same length as self.len(), since joining multiple patterns can increase s.len(), and corner cases will decrease s.len().

Provided Methods§

Source

fn len(&self) -> NonZeroUsize

Determines how many chars to look ahead, default 1.

The iterator will not stop prematurely because of look-ahead.

Source

fn sep(&self) -> Sep

Determines what to do with the matched char on separation.

See also sep_with

Trait Implementations§

Source§

impl<E: Debug> Pattern for Box<dyn Pattern<Err = E>>

Source§

type Err = E

Source§

fn matches(&mut self, c: char, s: &str) -> Result<bool, Self::Err>

Try matching a char in a pattern Read more
Source§

fn len(&self) -> NonZeroUsize

Determines how many chars to look ahead, default 1. Read more
Source§

fn sep(&self) -> Sep

Determines what to do with the matched char on separation. Read more

Implementations on Foreign Types§

Source§

impl Pattern for &str

Source§

type Err = Never

Source§

fn matches(&mut self, _: char, s: &str) -> Result<bool, Self::Err>

Source§

fn len(&self) -> NonZeroUsize

Source§

impl Pattern for &String

Source§

type Err = Never

Source§

fn matches(&mut self, _: char, s: &str) -> Result<bool, Self::Err>

Source§

fn len(&self) -> NonZeroUsize

Source§

impl Pattern for &[char]

Source§

type Err = Never

Source§

fn matches(&mut self, c: char, _: &str) -> Result<bool, Self::Err>

Source§

impl Pattern for char

Source§

type Err = Never

Source§

fn matches(&mut self, c: char, _: &str) -> Result<bool, Self::Err>

Source§

impl Pattern for isize

Source§

fn matches(&mut self, _: char, _: &str) -> Result<bool, Self::Err>

similar to peekn

Source§

type Err = Never

Source§

impl Pattern for String

Source§

type Err = Never

Source§

fn matches(&mut self, _: char, s: &str) -> Result<bool, Self::Err>

Source§

fn len(&self) -> NonZeroUsize

Source§

impl Pattern for RangeInclusive<char>

Source§

type Err = Never

Source§

fn matches(&mut self, c: char, _: &str) -> Result<bool, Self::Err>

Source§

impl Pattern for RangeTo<isize>

Source§

type Err = Never

Source§

fn matches(&mut self, _: char, _: &str) -> Result<bool, Self::Err>

Source§

impl<E: Debug> Pattern for Box<dyn Pattern<Err = E>>

Source§

type Err = E

Source§

impl<const N: usize> Pattern for [char; N]

Source§

type Err = Never

Source§

fn matches(&mut self, c: char, _: &str) -> Result<bool, Self::Err>

Implementors§

Source§

impl<F, B> Pattern for F
where F: FnMut(char) -> B, B: FallibleBool,

Source§

impl<P: FnMut(&str) -> B, B: FallibleBool> Pattern for SizedStrPredicate<P, B>

Source§

impl<P: FnMut(char, &str) -> B, B: FallibleBool> Pattern for SizedCharStrPredicate<P, B>

Source§

impl<P: SetSep> Pattern for SepConfig<P>

Source§

type Err = <P as Pattern>::Err

Source§

impl<const N: usize> Pattern for Interval<N>