rust-ux / uX

Non standard integer types like `u7`, `u9`, `u10`, `u63`, `i7`, `i9`
Apache License 2.0
119 stars 37 forks source link

Cannot pattern match #66

Closed Kyuuhachi closed 1 month ago

Kyuuhachi commented 4 months ago

Consts of these types cannot be used in patterns.

const A: u7 = u7::new(127);

fn foo() {
    match u7::new(127) {
        A => {}
        _ => {}
    }
}
error: to use a constant of type `u7` in a pattern, `u7` must be annotated with `#[derive(PartialEq, Eq)]`
  --> src/lib.rs:85:3
   |
85 |         A => {}
   |         ^
   |
   = note: the traits must be derived, manual `impl`s are not sufficient
   = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
chrysn commented 4 months ago

Implementing identity through the derived form would fix this, but it's a decision we have so far deferred. I've opened up #67 to come to a conclusion. If the outcome is "commit to mask-before", we can make the identity the structural one, and thus enable matching.