3 ms·
Do you think it's reasonable to make a Rust library that allows you to do Erlang style binary matching? That's what I was originally looking for when I found t
by adamnemecek 7y ago
Do you think it's reasonable to make a Rust library that allows you to do Erlang style binary matching?
That's what I was originally looking for when I found this.
- swsieber 7y agoIf your okay with macros, probably nightly only, then it seems reasonable. There is also slice matching on stable, which let's you match on parts of slices: https://github.com/rust-lang/rust/pull/67712/ https://github.com/rust-lang/rust/pull/67712/ . It went out in 1.42. It has some stuff which makes binary stuff easier, but not by much. But perhaps someday you'll get native binary matching in the language that's closer to what Erlang offers. It made it in the 1.42 release.
- archseer 7y ago^ agree with this, slice_patterns fulfilled my needs on the byte level at least. Bit level you could extract some parts of https://github.com/archseer/enigma/blob/master/enigma/src/bitstring.rs https://github.com/archseer/enigma/blob/master/enigma/src/bi... and wrap them in a macro but it's a bit clunky. I tend to just do it by hand (match a { a if a ^ 0b1100_0000 => ... } etc)