Haystack

Trait Haystack 

Source
pub trait Haystack: Copy + Clone {
    type Cursor: HaystackCursor;

    // Required methods
    fn len(&self) -> usize;
    fn cursor_at(&self, pos: usize) -> Self::Cursor;
    fn char_at(&self, pos: usize) -> Option<(char, usize)>;
    fn char_before(&self, pos: usize) -> Option<char>;
    fn starts_with(&self, pos: usize, literal: &str) -> bool;
    fn matches_range(
        &self,
        pos: usize,
        other_start: usize,
        other_end: usize,
    ) -> bool;
    fn find_byte(&self, byte: u8, pos: usize) -> Option<usize>;

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

A trait for text that can be searched by the regex engine. This abstraction allows searching over non-contiguous memory (like ropes) without flattening to a single string.

Required Associated Types§

Required Methods§

Source

fn len(&self) -> usize

Total length of the haystack in bytes

Source

fn cursor_at(&self, pos: usize) -> Self::Cursor

Get a cursor for streaming access starting at pos

Source

fn char_at(&self, pos: usize) -> Option<(char, usize)>

Get character at position

Source

fn char_before(&self, pos: usize) -> Option<char>

Get character before position

Source

fn starts_with(&self, pos: usize, literal: &str) -> bool

Check if haystack starts with literal at pos

Source

fn matches_range( &self, pos: usize, other_start: usize, other_end: usize, ) -> bool

Check if range matches another range

Source

fn find_byte(&self, byte: u8, pos: usize) -> Option<usize>

Find the first occurrence of a byte starting at pos. Returns None if not found.

Provided Methods§

Source

fn is_empty(&self) -> bool

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<'a> Haystack for &'a str

Source§

type Cursor = StrCursor<'a>

Source§

fn len(&self) -> usize

Source§

fn char_at(&self, pos: usize) -> Option<(char, usize)>

Source§

fn char_before(&self, pos: usize) -> Option<char>

Source§

fn starts_with(&self, pos: usize, literal: &str) -> bool

Source§

fn matches_range( &self, pos: usize, other_start: usize, other_end: usize, ) -> bool

Source§

fn cursor_at(&self, pos: usize) -> Self::Cursor

Source§

fn find_byte(&self, byte: u8, pos: usize) -> Option<usize>

Implementors§