These are chat archives for rust-lang/rust

14th
Sep 2018
Sam Johnson
@sam0x17
Sep 14 2018 02:28
@Virtuos86 thanks I will try that
Arun Kumar
@arunkumar413
Sep 14 2018 04:23
How does a debugger keep the mapping between the source code and the compiled code so that it knows which line of code is being executed.
Kelly Thomas Kline
@kellytk
Sep 14 2018 06:33
If Instant::now() causes a panic in browsers (stdweb -> wasm) how should I calculate instant.elapsed().as_millis()? (# of milliseconds from a moment in time)
Vitaly
@Virtuos86
Sep 14 2018 09:16

What's the standard way to implement a pipe operator for Rust?

https://doc.rust-lang.org/std/ops/trait.BitOr.html

Ichoran
@Ichoran
Sep 14 2018 13:40
@Virtuos86 - Sorry, I mean the functional programming pipe (known by a variety of names), not the pipe symbol. It just applies a function to yourself, so you can chain things in order. E.g. fn cube(x: i32) -> i32 { x*x*x } can be defined like that and then called with 12.pipe(cube) instead of cube(12), which can be handy at times.
trsh
@trsh
Sep 14 2018 14:01
What is best option to generate 64 bit random Hash (salt) in rust?
Lyle Mantooth
@IslandUsurper
Sep 14 2018 14:13
@Ichoran , I would expect a more traditional function pipe to return the function's return value, not the thing first passed into it. And most functional languages have everything be immutable, I believe, so doing it Rust probably would involve taking self by value instead of a reference. Several crates do this and call it the builder pattern, but they all return the same type when a function pipe wouldn't necessarily.
Maybe it could do &self. Not sure how it would all work out.
Ichoran
@Ichoran
Sep 14 2018 14:24
@IslandUsurper - Yes, I asked about pipe but posted tap.
Anyway, I guess the point is that people don't define this all the time, or have it in a library somewhere that everyone uses.
Lyle Mantooth
@IslandUsurper
Sep 14 2018 14:25
Right. I think it's because Rust isn't really a functional language. It's got a lot of the same features so you can write in that style, but it's not the same.
Ichoran
@Ichoran
Sep 14 2018 14:28
Oh, sure it's a functional language in the weaker sense of the term! Just because it has other great features too doesn't mean you can't use it that way. I agree it's not so awesome for defining general computations on monads due to a lack of HKTs, but heck, even R has pipe (%>%) and people use it all the time.
Anyway, so far tap is doing everything I need. I'll figure out pipe later.
Arun Kumar
@arunkumar413
Sep 14 2018 17:56
Is there rust tool to parse a . pug file?
Denis Lisov
@tanriol
Sep 14 2018 18:04
@Ichoran Like this?
Ichoran
@Ichoran
Sep 14 2018 19:08
@tanriol - Kind of, but I was hoping to avoid the Sized.
Ideally, anywhere you could write let x = thing(); let y = f(x); you should be able to write let y = thing().map_self(f).
John
@gitlabaccount624_gitlab
Sep 14 2018 22:34