The Any<I> struct allows you to combine multiple Needle implementations into a single search operation. It checks the provided needles in the order they are provided and returns the first successful match it finds.
Using fixed-size arrays or slices
You can pass arrays or slices of types that implement Needle directly to Any:
// Using an array of strings
let needle = Any(["we", "are", "here"]);
Using Any::boxed for heterogeneous needles
If you need to combine different types of needles (e.g., a String and an NBytes), you must use Any::boxed with a Vec<Box<dyn Needle>>:
use expectrl::{Any, NBytes};
let needle = Any::boxed(vec![
Box::new("we"),
Box::new(NBytes(3))
]);
use expectrl::{spawn, Any};
let mut p = spawn("cat").unwrap();
p.expect(Any(["we", "are", "here"])).unwrap();
// For mixed types:
let mut p = spawn("cat").unwrap();
p.expect(Any::boxed(vec![Box::new("we"), Box::new(NBytes(3))])).unwrap();