These are chat archives for rust-lang/rust

23rd
Feb 2017
Sebastian Blei
@iamsebastian
Feb 23 2017 07:37
Is it possible to match String { Regex … .is_match(s) => …, Regex … .is_match(s) => …? Meaning, check a string on different regexes within a match keyword?
Reason: Users are delivering different timestamps in CSV data (day only, with secods, without secs, etc. pp.)
Sebastian Blei
@iamsebastian
Feb 23 2017 07:46
VJ
@00imvj00
Feb 23 2017 10:31
i think, we should have special rust repo, where all the possible examples for all of these popular projects from start to end should be there, so any new comer can catch up very fast.
Sebastian Blei
@iamsebastian
Feb 23 2017 10:48
Is it possible to run cargo bench for debug, not release target?
Sebastian Blei
@iamsebastian
Feb 23 2017 11:03
Configured it via [profile.bench] in Cargo.toml.
Sebastian Blei
@iamsebastian
Feb 23 2017 13:03
Is it possible to create static items for RegExs? For example, I always check on three timestamps. And would initiate that RegexSet as static to reduce ressource usage.
But [E0015] tells:
error[E0015]: calls in statics are limited to constant functions, struct and enum constructors
  --> src/models/datetime.rs:12:31
   |
12 |   static TIMESTAMPS: RegexSet = RegexSet::new(&[
   |  _______________________________^ starting here...
Aleksey Kladov
@matklad
Feb 23 2017 13:05
Yep, static data in Rust needs to be constructable at compile time, there's no life before main.
You can use lazy_static though
Sebastian Blei
@iamsebastian
Feb 23 2017 13:06
Found it. Thanks, @matklad
Sebastian Blei
@iamsebastian
Feb 23 2017 13:13
Reduced iter time from 624.000ns to 4.000ns with static RegexSet. Glad, it was the bottle neck.
Ewan Higgs
@ehiggs
Feb 23 2017 13:30
Do you know the format of the timestamps? If so, you can try to parse your input using peg, or even slicing into the [u8].
Ewan Higgs
@ehiggs
Feb 23 2017 15:45
New cargo template for command line interfaces: https://github.com/rusttemplates/docopt
Michal 'vorner' Vaner
@vorner
Feb 23 2017 20:31
Hello. Is there something like . in haskell, to chain functions? So, if I have code like .take_while(|m| Ok(m.is_some())), I could write .take_while(Option::is_some . Ok) instead?
Ewan Higgs
@ehiggs
Feb 23 2017 21:04
stream.take_while(Option::is_some).map(|m| m.ok_or("Oh no")).collect::<Vec<_>>();