[Mesa-dev] Rust drivers in Mesa

Volker Weißmann volker.weissmann at gmx.de
Sat Oct 3 15:40:21 UTC 2020


> 2. Rust's enums look awesome but are only mostly awesome:
>      a. Pattern matching on them can lead to some pretty deep
> indentation which is a bit annoying.
>      b. There's no good way to have multiple cases handled by the same
> code like you can with a C switch; you have to either repeat it or
> break it out into a generic helper.

Do you know that you can use "|" for having multiple cases handled by the same code?

enum MyEnum {
	A,
	B,
	C
}
fn main() {
	let val = MyEnum::A;
	match val {
		MyEnum::A | MyEnum::B => {println!("case A or case B");},
		MyEnum::C => {println!("case C");}
	}
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20201003/c58cab75/attachment.htm>


More information about the mesa-dev mailing list