These are chat archives for rust-lang/rust

Sep 2018
Sam Johnson
Sep 14 2018 02:28
@Virtuos86 thanks I will try that
Arun Kumar
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
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)
Sep 14 2018 09:16

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

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.
Sep 14 2018 14:01
What is best option to generate 64 bit random Hash (salt) in rust?
Lyle Mantooth
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.
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
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.
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
Sep 14 2018 17:56
Is there rust tool to parse a . pug file?
Denis Lisov
Sep 14 2018 18:04
@Ichoran Like this?
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).
Sep 14 2018 22:34