Awesome use of unreachable!
On Tue, Apr 8, 2014 at 4:53 PM, Peter Marheine <[email protected]> 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(), bits 4 to 8 { > 0 => DivideBy1, > 1 => DivideBy2, > 2 => DivideBy4, > _ => UnknownDivisor > }; > > On Fri, Apr 4, 2014 at 7:11 AM, Vladimir Pouzanov <[email protected]> > wrote: > > 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 <[email protected]> > 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: > >> 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 > >> generalize over the bit-length and integers, and that's going to require > >> generics with int parameters and work to add those. > >> > > > > > > > > -- > > Sincerely, > > Vladimir "Farcaller" Pouzanov > > http://farcaller.net/ > > > > _______________________________________________ > > Rust-dev mailing list > > [email protected] > > https://mail.mozilla.org/listinfo/rust-dev > > > > > > -- > Peter Marheine > Don't Panic > -- Sincerely, Vladimir "Farcaller" Pouzanov http://farcaller.net/
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
