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: IImplementations§
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)
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§
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> 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