Struct expectrl::Any

source ·
pub struct Any<I>(pub I);
Expand description

Any matches uses all provided lookups and returns a match from a first successfull match.

It does checks lookups in order they were provided.

Example

use expectrl::{spawn, Any};

let mut p = spawn("cat").unwrap();
p.expect(Any(["we", "are", "here"])).unwrap();

To be able to combine different types of lookups you can call Any::boxed.

use expectrl::{spawn, Any, NBytes};

let mut p = spawn("cat").unwrap();
p.expect(Any::boxed(vec![Box::new("we"), Box::new(NBytes(3))])).unwrap();

Tuple Fields§

§0: I

Implementations§

source§

impl Any<Vec<Box<dyn Needle>>>

source

pub fn boxed(v: Vec<Box<dyn Needle>>) -> Self

Boxed expectes a list of Boxed lookups.

Examples found in repository?
examples/expect_line.rs (lines 9-13)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn main() {
    let mut session = expectrl::spawn("ls -al").expect("Can't spawn a session");

    loop {
        let m = session
            .expect(Any::boxed(vec![
                Box::new("\r"),
                Box::new("\n"),
                Box::new(Eof),
            ]))
            .expect("Expect failed");

        println!("{:?}", String::from_utf8_lossy(m.as_bytes()));

        let is_eof = m[0].is_empty();
        if is_eof {
            break;
        }

        if m[0] == [b'\n'] {
            continue;
        }

        println!("{:?}", String::from_utf8_lossy(&m[0]));
    }
}

Trait Implementations§

source§

impl<I: Debug> Debug for Any<I>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Needle for Any<&[T]>where T: Needle,

source§

fn check(&self, buf: &[u8], eof: bool) -> Result<Vec<Match>, Error>

Function returns all matches that were occured.
source§

impl<T, const N: usize> Needle for Any<&[T; N]>where T: Needle,

source§

fn check(&self, buf: &[u8], eof: bool) -> Result<Vec<Match>, Error>

Function returns all matches that were occured.
source§

impl<T, const N: usize> Needle for Any<[T; N]>where T: Needle,

source§

fn check(&self, buf: &[u8], eof: bool) -> Result<Vec<Match>, Error>

Function returns all matches that were occured.
source§

impl<T> Needle for Any<Vec<T>>where T: Needle,

source§

fn check(&self, buf: &[u8], eof: bool) -> Result<Vec<Match>, Error>

Function returns all matches that were occured.

Auto Trait Implementations§

§

impl<I> RefUnwindSafe for Any<I>where I: RefUnwindSafe,

§

impl<I> Send for Any<I>where I: Send,

§

impl<I> Sync for Any<I>where I: Sync,

§

impl<I> Unpin for Any<I>where I: Unpin,

§

impl<I> UnwindSafe for Any<I>where I: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.