Awesome use of unreachable!
On Tue, Apr 8, 2014 at 4:53 PM, Peter Marheine wrote:
> I had a go at building a macro to do this sort of thing, and it turned
> out to be easier than I expected.
>
> https://gist.github.com/tari/10144385
>
> Use like this:
> let x = match_bitfield!(do_something(
I had a go at building a macro to do this sort of thing, and it turned
out to be easier than I expected.
https://gist.github.com/tari/10144385
Use like this:
let x = match_bitfield!(do_something(), bits 4 to 8 {
0 => DivideBy1,
1 => DivideBy2,
2 => DivideBy4,
_
I've submitted an RFC for this one:
https://github.com/rust-lang/rfcs/pull/29
On Sat, Mar 29, 2014 at 6:14 PM, Bill Myers wrote:
> I think the best solution is to add uN and sN types where N is not a power
> of two, which LLVM should already support.
>
> Then you can write your match like this:
I think the best solution is to add uN and sN types where N is not a power of
two, which LLVM should already support.
Then you can write your match like this:
match (val >> 6) as u2
{
...
}
And it will work as desired.
Biggest issue is that to make it work nicely you'd need to add some way to
WOW procedural macros! Hadn't seen before that rust has those. that's so
cool
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev
On Fri, Mar 28, 2014 at 10:43 AM, Peter Marheine wrote:
> On Fri, Mar 28, 2014 at 9:30 AM, Jared Forsyth wrote:
>> Is rust's macro system powerful enough to do calculations, such that you
>> would be able to guarantee that the provided patterns were exhaustive?
>> From what I've seen, the macro s
Whoops, I accidentally sent this to Peter instead of the whole list...
This doesn't even need to be a very hard feature to implement, or require
any new syntax. All that needs to happen is for the compiler to know that "&
0b11" means the only viable options are 00, 01, 10, and 11. True?
val[6..7]
Adding the list for Evan's benefit. :)
>> On Fri, Mar 28, 2014 at 10:21 AM, Evan G wrote:
>> > Sorry, I didn't see your message about an n-bit integer type. It sounds
>> > like
>> > a great solution! I was just responding to the "warrant a core feature".
>> > I'm
>> > just saying it doesn't reall
On Fri, Mar 28, 2014 at 9:57 AM, Evan G wrote:
> This doesn't even need to be a very hard feature to implement, or require
> any new syntax. All that needs to happen is for the compiler to know that "&
> 0b11" means the only viable options are 00, 01, 10, and 11. True?
This is true, but doesn't m
On Fri, Mar 28, 2014 at 9:30 AM, Jared Forsyth wrote:
> Is rust's macro system powerful enough to do calculations, such that you
> would be able to guarantee that the provided patterns were exhaustive?
> From what I've seen, the macro system can mostly just do syntax expansion -
> not logic, etc.
On Fri, Mar 28, 2014 at 7:56 AM, Peter Marheine wrote:
> This sounds like a good use case for a macro, though
>
Is rust's macro system powerful enough to do calculations, such that you
would be able to guarantee that the provided patterns were exhaustive?
>From what I've seen, the macro system c
I think it's a great little feature that would set rust apart in the
embedded development space, and perfectly viable to be a compiler feature.
It's not for everyone, but the people that would find it useful would find
it REALLY useful. Rust might even find a niche in safety critical software.
-
While potentially useful, I don't think this use case is common enough
to warrant being a core feature. This sounds like a good use case for
a macro, though. Something like:
match bitfield!(val, 6..7) {
0b00 => ...,
0b01 => ...,
0b10 => ...,
0b11 => ...
}
c
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 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
> tho
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 wrote:
> There's one thing that I often have to deal in embedded code —
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
16 matches
Mail list logo