guard_let

doc.rs crates.io

Guard let for rust

Usage

```rust

use guardlet::guardlet;

enum Enum { A(String), B(usize), C(Struct), }

struct Struct { foo: String, }

fn eatstring(: String) {}

[guard_let]

fn simple_ident() { let v = Enum::A(String::from(""));

guard_let!(v as Enum::A(s), {
    // Type of v is Enum at here.
    println!("v is not A: {:?}", v);
    return;
});

// Type of s is String
eat_string(s)

}

[guard_let]

fn pattern() { let v = Enum::A(String::from(""));

guard_let!(v as Enum::C(Struct { foo }), {
    // Type of v is Enum at here.
    println!("v is not C: {:?}", v);
    return;
});

// Type of s is String
eat_string(foo)

}

```

License

MIT