pub struct Captures { /* private fields */ }
Expand description
Captures is a represention of matched pattern.
It might represent an empty match.
Implementations§
source§impl Captures
impl Captures
sourcepub fn get(&self, index: usize) -> Option<&[u8]>
pub fn get(&self, index: usize) -> Option<&[u8]>
get returns a match by index.
Examples found in repository?
examples/python.rs (line 14)
4 5 6 7 8 9 10 11 12 13 14 15 16
fn main() {
let mut p = spawn_python().unwrap();
p.execute("import platform").unwrap();
p.send_line("platform.node()").unwrap();
let found = p.expect(Regex(r"'.*'")).unwrap();
println!(
"Platform {}",
String::from_utf8_lossy(found.get(0).unwrap())
);
}
sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
as_bytes returns all bytes involved in a match, e.g. before the match and in a match itself.
In most cases the returned value equeals to concatanted Self::before and Self::matches. But sometimes like in case of crate::Regex it may have a grouping so Self::matches might overlap, therefore it will not longer be true.
Examples found in repository?
examples/expect_line.rs (line 16)
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<'a> IntoIterator for &'a Captures
impl<'a> IntoIterator for &'a Captures
source§impl PartialEq<Captures> for Captures
impl PartialEq<Captures> for Captures
impl Eq for Captures
impl StructuralEq for Captures
impl StructuralPartialEq for Captures
Auto Trait Implementations§
impl RefUnwindSafe for Captures
impl Send for Captures
impl Sync for Captures
impl Unpin for Captures
impl UnwindSafe for Captures
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