Struct xfind::StreamFinder[][src]

pub struct StreamFinder<'n> { /* fields omitted */ }
Expand description

A substring searcher for stream searches.

Implementations

Creates a new StreamFinder for the given needle.

Examples

use xfind::StreamFinder;

let finder = StreamFinder::new(b"rust");

Returns the needle that this finder searches for.

Examples

use xfind::StreamFinder;

let finder = StreamFinder::new(b"rust");
assert_eq!(finder.needle(), b"rust");

Returns the index of the first occurrence of the given needle in the stream.

Examples

use std::io::{self, Cursor};
use xfind::StreamFinder;

fn main() -> io::Result<()> {
    let mut stream = Cursor::new(b"rusty rust");
    let finder = StreamFinder::new(b"rust");

    let pos = finder.find(&mut stream).transpose()?;
    assert_eq!(pos, Some(0));

    Ok(())
}

Returns the index of the last occurrence of the given needle in the stream.

Panics

Panics if the length of the stream is greater than usize::MAX.

Examples

use std::io::{self, Cursor};
use xfind::StreamFinder;

fn main() -> io::Result<()> {
    let mut stream = Cursor::new(b"rusty rust");
    let finder = StreamFinder::new(b"rust");

    let pos = finder.rfind(&mut stream).transpose()?;
    assert_eq!(pos, Some(6));

    Ok(())
}

Returns an iterator over all occurrences of the given needle in the stream.

Examples

use std::io::{self, Cursor};
use xfind::StreamFinder;

fn main() -> io::Result<()> {
    let mut stream = Cursor::new(b"rusty rust");
    let finder = StreamFinder::new(b"rust");

    let mut iter = finder.find_iter(&mut stream);
    assert_eq!(iter.next().transpose()?, Some(0));
    assert_eq!(iter.next().transpose()?, Some(6));
    assert_eq!(iter.next().transpose()?, None);

    Ok(())
}

Returns a reverse iterator over all occurrences of the given needle in the stream.

Errors

Returns an I/O error if seeking to the end of the stream failed.

Panics

Panics if the length of the stream is greater than usize::MAX.

Examples

use std::io::{self, Cursor};
use xfind::StreamFinder;

fn main() -> io::Result<()> {
    let mut stream = Cursor::new(b"rusty rust");
    let finder = StreamFinder::new(b"rust");

    let mut iter = finder.rfind_iter(&mut stream)?;
    assert_eq!(iter.next().transpose()?, Some(6));
    assert_eq!(iter.next().transpose()?, Some(0));
    assert_eq!(iter.next().transpose()?, None);

    Ok(())
}

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.