jeudi 14 décembre 2017

If Statement Involving Enums and Other Logic

I have an enum:

#[derive(PartialEq, Eq)]
enum Foo {
    A,
    B(usize),
}

I can use it in if statements involving other logic like baz:

fn bar(foo: &Foo, baz: bool) {
    if foo == &Foo::B(3) || baz {
        println!("Do stuff")
    }
}

However, this won't compile:

fn bar(foo: &Foo, baz: bool) {
    if foo == &Foo::B(_) || baz {
        println!("Do stuff")
    }
}

How do I use it in an if statement when I don't care what value B contains?

Aucun commentaire:

Enregistrer un commentaire