Struct CapturesUnsafe

Source
pub struct CapturesUnsafe<'b> { /* private fields */ }
Expand description

Unsafe version of Captures, needed for gmatch_captures

Implementations§

Source§

impl<'b> CapturesUnsafe<'b>

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.