Skip to main content

Input

Trait Input 

Source
pub trait Input {
    type Match<'t>
       where Self: 't;

    // Required methods
    fn len(&self) -> usize;
    fn as_bytes(&self) -> &[u8] ;
    fn is_char_boundary(&self, ix: usize) -> bool;
    fn is_ascii(&self) -> bool;
    fn prev_codepoint_ix(&self, i: usize) -> usize;
    fn make_match<'t>(&'t self, start: usize, end: usize) -> Self::Match<'t>;
    fn advance_position(&self, i: usize) -> usize;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A trait abstracting over haystack types for regex matching.

This trait is implemented for str, String, [u8], and [u8; N], allowing regex methods to work with both UTF-8 text and raw byte slices.

When the regex is compiled with BytesMode::Ascii, patterns like . will match any byte in [u8] input. Without bytes mode, . only matches valid UTF-8 codepoints even in byte slices.

The associated type Match<'t> is the concrete match type returned for a given input: Match<'t> for string inputs, MatchBytes<'t> for byte slice inputs.

Required Associated Types§

Source

type Match<'t> where Self: 't

The match type produced for this input.

Required Methods§

Source

fn len(&self) -> usize

Returns the length of the input in bytes.

Source

fn as_bytes(&self) -> &[u8]

Returns the input as a raw byte slice.

Source

fn is_char_boundary(&self, ix: usize) -> bool

Returns true if ix is a valid position between UTF-8 codepoints.

Source

fn is_ascii(&self) -> bool

Returns true if the entire input is ASCII.

Source

fn prev_codepoint_ix(&self, i: usize) -> usize

Steps back one codepoint from position i, returning the start position.

Source

fn make_match<'t>(&'t self, start: usize, end: usize) -> Self::Match<'t>

Construct a match from byte offsets.

Source

fn advance_position(&self, i: usize) -> usize

Advance past the codepoint at position i.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the input is empty.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Input for String

Source§

type Match<'t> = Match<'t>

Source§

fn len(&self) -> usize

Source§

fn as_bytes(&self) -> &[u8]

Source§

fn is_char_boundary(&self, ix: usize) -> bool

Source§

fn is_ascii(&self) -> bool

Source§

fn prev_codepoint_ix(&self, i: usize) -> usize

Source§

fn make_match<'t>(&'t self, start: usize, end: usize) -> Match<'t>

Source§

fn advance_position(&self, i: usize) -> usize

Source§

impl Input for [u8]

Source§

type Match<'t> = MatchBytes<'t>

Source§

fn len(&self) -> usize

Source§

fn as_bytes(&self) -> &[u8]

Source§

fn is_char_boundary(&self, ix: usize) -> bool

Source§

fn is_ascii(&self) -> bool

Source§

fn prev_codepoint_ix(&self, i: usize) -> usize

Source§

fn make_match<'t>(&'t self, start: usize, end: usize) -> MatchBytes<'t>

Source§

fn advance_position(&self, i: usize) -> usize

Source§

impl Input for str

Source§

type Match<'t> = Match<'t>

Source§

fn len(&self) -> usize

Source§

fn as_bytes(&self) -> &[u8]

Source§

fn is_char_boundary(&self, ix: usize) -> bool

Source§

fn is_ascii(&self) -> bool

Source§

fn prev_codepoint_ix(&self, i: usize) -> usize

Source§

fn make_match<'t>(&'t self, start: usize, end: usize) -> Match<'t>

Source§

fn advance_position(&self, i: usize) -> usize

Source§

impl<S: Input + ?Sized> Input for &S

Source§

type Match<'t> = <S as Input>::Match<'t> where Self: 't

Source§

fn len(&self) -> usize

Source§

fn as_bytes(&self) -> &[u8]

Source§

fn is_char_boundary(&self, ix: usize) -> bool

Source§

fn is_ascii(&self) -> bool

Source§

fn prev_codepoint_ix(&self, i: usize) -> usize

Source§

fn make_match<'t>(&'t self, start: usize, end: usize) -> Self::Match<'t>

Source§

fn advance_position(&self, i: usize) -> usize

Source§

impl<const N: usize> Input for [u8; N]

Source§

type Match<'t> = MatchBytes<'t>

Source§

fn len(&self) -> usize

Source§

fn as_bytes(&self) -> &[u8]

Source§

fn is_char_boundary(&self, ix: usize) -> bool

Source§

fn is_ascii(&self) -> bool

Source§

fn prev_codepoint_ix(&self, i: usize) -> usize

Source§

fn make_match<'t>(&'t self, start: usize, end: usize) -> MatchBytes<'t>

Source§

fn advance_position(&self, i: usize) -> usize

Implementors§