These are chat archives for rust-lang/rust

16th
Dec 2018
David O'Connor
@David-OConnor
Dec 16 2018 00:15
I think this is what Python's re.sub does
James McCoy
@jamessan
Dec 16 2018 00:18
replace and replace_all support the same functionality -- https://docs.rs/regex/1.1.0/regex/struct.Regex.html#method.replace_all
rep must satisfy the Replacer trait, which can be a function
David O'Connor
@David-OConnor
Dec 16 2018 00:23
Thanks; looks like the soln!
David O'Connor
@David-OConnor
Dec 16 2018 00:35

Struggling a bit with expected sigs. So get_excited should look like this?

let get_excited = |match_grp: regex::Captures| match_grp.name("replace_this").unwrap().as_str().to_string() + "!";

Eg first we extract the match group by name (in this case only one thing), then we unwrap the option, then call .as_str() to turn it into a string, and the rest is my example processing.
Error: expected signature of `for<'r, 's> fn(&'r regex::re_unicode::Captures<'s>) -> _

James McCoy
@jamessan
Dec 16 2018 00:43
The two differences I see in the error vs. your example are 1) you should be borrowing the argument, not taking ownership 2) it's expecting the unicode version of Captures
David O'Connor
@David-OConnor
Dec 16 2018 01:17
Thank you very much: Annotating Captures with & prepended works! Also had a greediness issue, fixed by placing ? before close parens on match group. What do you mean by unicode version?
James McCoy
@jamessan
Dec 16 2018 01:42
regex::Captures vs. regex::re_unicode::Captures
If adding the & solved the issue, then that's great
David O'Connor
@David-OConnor
Dec 16 2018 02:32
Thanks dude; much apprec
Dermot Haughey
@hderms
Dec 16 2018 02:37
anyone care to tell me best practices for taking a u16 and pulling out various chunk out of it i.e. bits 0-4 into this field in the struct
https://justinmeiners.github.io/lc3-vm/#1:6 trying to learn Rust by doing this guide. Currently on the section "Add"
something like this seems good: https://github.com/dzamlo/rust-bitfield
Michal 'vorner' Vaner
@vorner
Dec 16 2018 08:43
@David-OConnor The docs.rs did catch up. It shows all the libs I published yesterday now.
LeapM
@LeapM
Dec 16 2018 14:05
hello can someone please help with #![feature(prelude_import)]? what is it for? where can I find more information about it?
David O'Connor
@David-OConnor
Dec 16 2018 15:03
@vorner same!
Michal 'vorner' Vaner
@vorner
Dec 16 2018 15:45
Hmm. I'm hitting a strange behaviour here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=88b21c3520dead8c751e9818c2f1e001. It seems it drops inspector first, days later on. But according to this: https://github.com/rust-lang/rfcs/blob/master/text/1857-stabilize-drop-order.md#tuples-structs-and-enum-variants, it should be the other way around. Or am I reading it wrong?
Michal 'vorner' Vaner
@vorner
Dec 16 2018 16:21
Never mind. Turns out this is because it's unpacked and no longer a tuple.
knewt
@knewt
Dec 16 2018 17:12
hmm, any idea why rust would complain "transmute called with types of different sizes” where the only difference is the lifetime?