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>>>
impl Any<Vec<Box<dyn Needle>>>
sourcepub fn boxed(v: Vec<Box<dyn Needle>>) -> Self
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more