pub struct CapturesUnsafe<'b> { /* private fields */ }
Expand description
Unsafe version of Captures, needed for gmatch_captures
Implementations§
Source§impl<'b> CapturesUnsafe<'b>
impl<'b> CapturesUnsafe<'b>
Sourcepub fn get(&self, i: usize) -> &'b str
pub fn get(&self, i: usize) -> &'b str
get the capture as a string slice
Examples found in repository?
examples/iter.rs (line 26)
3fn main() {
4 //~ let mut m = lp::LuaPattern::new("hello%");
5 //~ m.matches("hello");
6 //~ println!("ok");
7
8 let mut m = lp::LuaPattern::new("(%a+)");
9 let mut iter = m.gmatch("one two three");
10 assert_eq!(iter.next(), Some("one"));
11 assert_eq!(iter.next(), Some("two"));
12 assert_eq!(iter.next(), Some("three"));
13 assert_eq!(iter.next(), None);
14
15 let mut m = lp::LuaPattern::new("%S+");
16 let split: Vec<_> = m.gmatch("dog cat leopard wolf").collect();
17 assert_eq!(split, &["dog", "cat", "leopard", "wolf"]);
18
19 let mut m = lp::LuaPattern::new("%s*(%S+)%s*=%s*(.-);");
20 let cc = m.captures(" hello= bonzo dog;");
21 assert_eq!(cc[0], " hello= bonzo dog;");
22 assert_eq!(cc[1], "hello");
23 assert_eq!(cc[2], "bonzo dog");
24
25 for cc in m.gmatch_captures("hello=bonzo dog; bye=cat;") {
26 println!("'{}'='{}'", cc.get(1), cc.get(2));
27 }
28
29 let mut m = lp::LuaPattern::new("%$(%S+)");
30 let res = m.gsub_with("hello $dolly you're so $fine", |cc| {
31 cc.get(1).to_uppercase()
32 });
33 assert_eq!(res, "hello DOLLY you're so FINE");
34
35 let mut m = lp::LuaPattern::new("(%S+)%s*=%s*([^;]+);");
36 let res = m.gsub_with("alpha=bonzo; beta=felix;", |cc| {
37 format!("{}:'{}',", cc.get(1), cc.get(2))
38 });
39 assert_eq!(res, "alpha:'bonzo', beta:'felix',");
40}
Auto Trait Implementations§
impl<'b> Freeze for CapturesUnsafe<'b>
impl<'b> RefUnwindSafe for CapturesUnsafe<'b>
impl<'b> !Send for CapturesUnsafe<'b>
impl<'b> !Sync for CapturesUnsafe<'b>
impl<'b> Unpin for CapturesUnsafe<'b>
impl<'b> UnwindSafe for CapturesUnsafe<'b>
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