Struct 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)
4fn main() {
5    let mut session = expectrl::spawn("ls -al").expect("Can't spawn a session");
6
7    loop {
8        let m = session
9            .expect(Any::boxed(vec![
10                Box::new("\r"),
11                Box::new("\n"),
12                Box::new(Eof),
13            ]))
14            .expect("Expect failed");
15
16        println!("{:?}", String::from_utf8_lossy(m.as_bytes()));
17
18        let is_eof = m[0].is_empty();
19        if is_eof {
20            break;
21        }
22
23        if m[0] == [b'\n'] {
24            continue;
25        }
26
27        println!("{:?}", String::from_utf8_lossy(&m[0]));
28    }
29}

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> Freeze for Any<I>
where I: Freeze,

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.