Struct patterns

In struct patterns reference, there's a note:

A struct pattern is refutable if the PathInExpression resolves to a constructor of an enum with more than one variant

... but I can't imagine what it would look like in code. How can I create a refutable struct pattern with enum like mentioned above?

fn main() {
    let x = Test::A(1);
    match x {
        //?
    };
}

enum Test {
    A(u32),
    B(u32)
}

For example:

fn main() {
    let x = Test::A(1);
    match x {
        Test::B { field } => {},
        _ => {},
    }
}

enum Test {
    A(u32),
    B {
        field: u32
    }
}

Isn't the example below also refutable without the need of second enum variant? It looks like it's still a struct pattern

fn main() {
    let x = Test::B {
        field: 0
    };
    match x {
        Test::B { field: 100 } => println!("first arm"),
        _ => println!("second arm"),
    }
}

enum Test {
    B {
        field: u32
    }
}

EDIT:
Nevermind, I forgot about this:

A struct pattern is refutable if the PathInExpression resolves to a constructor of an enum with more than one variant, or one of its subpatterns is refutable.


Oh, I think I get it now!
There's a need for this:

Test::B { field } => {},

because without the exact syntax we wouldn't deal with struct pattern, but rather a path pattern, right?
Also, if there was just one variant, it wouldn't be refutable (because there's no way one variant won't match)

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.