Sorry, that's definitely a typo, (val >> 6) & 0b11 makes sense, (val &
0b11) >> 6 does not.


On Fri, Mar 28, 2014 at 1:04 PM, Clark Gaebel <cgae...@uwaterloo.ca> wrote:

> I like this! Although I think that match might've been better written
> `(val >> 6) & 0b11`, but it'd be really nice for the compiler to catch
> those type of errors!
>
>   - Clark
>
>
> On Fri, Mar 28, 2014 at 5:54 AM, Vladimir Pouzanov <farcal...@gmail.com>wrote:
>
>> There's one thing that I often have to deal in embedded code — doing
>> match on a few bits from an I/O register, which is commonly u32:
>>
>> let val : u32 = ...;
>> match (val & 0b11) >> 6 {
>>   0b00 => ...,
>>   0b01 => ...,
>>   0b10 => ...,
>>   _ => {}
>> }
>>
>> You can clearly see two problems here: I need to provide a catch-all
>> match, even if the code guarantees a limited set of values; also I lost
>> 0b11, and there's no warning due to catch all.
>>
>> Is it possible to make rustc aware of such cases?
>>
>> What would be totally awesome is some kind of [] operator for ints, that
>> would extract bits, like that:
>>
>> match val[6..7] { ... }
>>
>> Is that something of interest to community? I would be willing to write
>> an RFC for that, and possibly extend the compiler.
>>
>> --
>> Sincerely,
>> Vladimir "Farcaller" Pouzanov
>> http://farcaller.net/
>>
>> _______________________________________________
>> Rust-dev mailing list
>> Rust-dev@mozilla.org
>> https://mail.mozilla.org/listinfo/rust-dev
>>
>>
>
>
> --
> Clark.
>
> Key ID     : 0x78099922
> Fingerprint: B292 493C 51AE F3AB D016  DD04 E5E3 C36F 5534 F907
>



-- 
Sincerely,
Vladimir "Farcaller" Pouzanov
http://farcaller.net/
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to