These are chat archives for rust-lang/rust

12th
Nov 2017
Mark Simulacrum
@Mark-Simulacrum
Nov 12 2017 01:00
That, or type ascription, but it's unstable
Either way I think you'd end up with Result<Type, _>
Hans W. Uhlig
@huhlig
Nov 12 2017 02:27
ok, I am feeling a bit dumb. Does this do what I think it does
type MapFunction<I: Datum, O: Datum> = Fn(I) -> O;
red75prime
@red75prime
Nov 12 2017 05:54
@huhlig, probably no. MapFunction is a trait-object type for Fn(I)->O trait.
Sherab Giovannini
@Shaddy
Nov 12 2017 11:41
@jplatte
how can I a playground to do a cargo bench? is it possible?
Jonas Platte
@jplatte
Nov 12 2017 11:42
@Shaddy Should be possible. Just paste your code, and select Nightly at the top.
Sherab Giovannini
@Shaddy
Nov 12 2017 11:42
but it woundnt start as cargo bench
Jonas Platte
@jplatte
Nov 12 2017 11:43
Oh, it has a run button still instead of test?
yup
Jonas Platte
@jplatte
Nov 12 2017 11:43
I guess it detects whether tests are there by looking for the #[test] attribute
Sherab Giovannini
@Shaddy
Nov 12 2017 11:44
in the case of bench, it is #bench attribute
Jonas Platte
@jplatte
Nov 12 2017 11:44
Yeah I know
Sherab Giovannini
@Shaddy
Nov 12 2017 11:44
anyway, can't even test
The playground needs to know to run in test mode rather than regular binary mode though ^^
Sherab Giovannini
@Shaddy
Nov 12 2017 11:46
how you did that!
Jonas Platte
@jplatte
Nov 12 2017 11:47
Hm, it doesn't print the benchmark results :D
Sherab Giovannini
@Shaddy
Nov 12 2017 11:47
yeah
xD
Jonas Platte
@jplatte
Nov 12 2017 11:48
maybe worth a feature request over at https://github.com/integer32llc/rust-playground/issues
but the playgroud probably is a pretty bad environment for running benchmarks..
huh
Sherab Giovannini
@Shaddy
Nov 12 2017 11:50
well, but is really fancy to have a platform where we can share the results
Jonas Platte
@jplatte
Nov 12 2017 11:50
So when I run your test locally (excluding retain because there is no code for it and it wouldn't be comparable anyway)
I get basically the same results between filter and split
but replace is slower
Sherab Giovannini
@Shaddy
Nov 12 2017 11:51
yes, that's kinda the same results I got
Jonas Platte
@jplatte
Nov 12 2017 11:51
actually, filter is always a tiny bit faster
Sherab Giovannini
@Shaddy
Nov 12 2017 11:51
filter and split were closer, but in my case split was tiny faster
Jonas Platte
@jplatte
Nov 12 2017 11:51
Well filter and split were further apart in your test
And interestingly, my machine seems to have far less jitter in the test results
jplatte@jp-desktop ~/undash (git)-[master] % cargo bench
    Finished release [optimized] target(s) in 0.0 secs
     Running target/release/deps/undash-7ef87b8a3db74b47

running 3 tests
test bench_filter  ... bench:         160 ns/iter (+/- 8)
test bench_replace ... bench:         256 ns/iter (+/- 7)
test bench_split   ... bench:         167 ns/iter (+/- 4)

test result: ok. 0 passed; 0 failed; 0 ignored; 3 measured; 0 filtered out
Sherab Giovannini
@Shaddy
Nov 12 2017 11:53
jitter?
Jonas Platte
@jplatte
Nov 12 2017 11:54
standard deviation, or whatever
the +/- thing
Sherab Giovannini
@Shaddy
Nov 12 2017 11:55
let me test one more time
unning 3 tests
test bench_filter  ... bench:         134 ns/iter (+/- 33)
test bench_replace ... bench:         246 ns/iter (+/- 134)
test bench_split   ... bench:         192 ns/iter (+/- 35)

test result: ok. 0 passed; 0 failed; 0 ignored; 3 measured; 0 filtered out


sherab at MBP-de-Sherab in ~/exercism/rust/isbn-verifier
$ cargo bench
    Finished release [optimized] target(s) in 0.0 secs
     Running target/release/deps/isbn_verifier-8e454a2119b12b61

running 3 tests
test bench_filter  ... bench:         119 ns/iter (+/- 44)
test bench_replace ... bench:         248 ns/iter (+/- 133)
test bench_split   ... bench:         186 ns/iter (+/- 143)

test result: ok. 0 passed; 0 failed; 0 ignored; 3 measured; 0 filt
filter is the winner by far
Jonas Platte
@jplatte
Nov 12 2017 11:56
I'll have a look at the generated code :D
seen as the playground has the option of doing that ^^
Sherab Giovannini
@Shaddy
Nov 12 2017 11:56
yup, i'll check it as well
Jonas Platte
@jplatte
Nov 12 2017 11:57
(make sure to put it in release mode though :D)
Sherab Giovannini
@Shaddy
Nov 12 2017 11:57
yes yes
ill check with IDA :D
Jonas Platte
@jplatte
Nov 12 2017 11:57
Oh you actually know this stuff, huh? ^^
also I don't think switching to release on playground did anything :S
Sherab Giovannini
@Shaddy
Nov 12 2017 11:58
yup, I started mainly as a reverse engineer
Jonas Platte
@jplatte
Nov 12 2017 11:58
nice :smile:
Sherab Giovannini
@Shaddy
Nov 12 2017 12:05
it seems that replace constructs a pattern searcher, call core::str::pattern::StrSearcher::new::hb8c7b909c8c5f0f8
which is the penalty over split/filter
that only walks a vector
Zoran Zaric
@zoranzaric
Nov 12 2017 15:27
I‘m still fighting basic concepts and syntax. For this I have a little toy project, that uses hyper. What would the most idiomatic way of adding some state like a counter to the webserver be?
Jente Van Heuverswyn
@JenteVH
Nov 12 2017 16:52
Can someone help me out here? I'm trying to get going with Rust but the workflow is not entirely clear to me. Say I download a git repo and cargo run it. Everything works fine. Now I make changes to some code. Do I have to manually restart the program and navigate to where I made the change in said program? Other languages have solutions to this. What's the solution for Rust?
Aleksey Kladov
@matklad
Nov 12 2017 16:54
You are looking for something like hot-reload of code? It's not possible in Rust, at least not in any direct manner.
Jente Van Heuverswyn
@JenteVH
Nov 12 2017 16:56
@matklad Perhaps something of the like, yes.
So are you telling me when you're working on a project you are constantly manually rebuilding, restarting and navigating to your change? This seems cumbersome
Aleksey Kladov
@matklad
Nov 12 2017 16:58
I usually have a test for the thing I am developing at the moment, and my IDE has shortcuts for running a specific test, or rerunning tests, so for me it's "1. code-code-code 2. Hit Ctrl+R, 1".
Jente Van Heuverswyn
@JenteVH
Nov 12 2017 17:00
@matklad I guess that makes sense most of the time. What about GUI related things?
Any specific workflow there?
Will
@tavurth
Nov 12 2017 17:02
Hi everyone)
I'm trying to write a Vec<&'a Box<Trait>> implementation, but I'm running into some difficulties
Could anyone give me some pointers?
Aleksey Kladov
@matklad
Nov 12 2017 17:03

There are few GUI applications in Rust at the moment, mostly because writing cross platform native GUI is quite hard at the moment.

The few GUI applications I know are Servo and games, and they usually have some custom infrastructure to do live reloading.

In Servo, the whole GUI is written in JS IIRC, for games it's usually possible to move a lot of things from code into data.
@tavurth the double indirection in Vec<Box<Trait>> seems suspicious.
Usually, one wants either Vec<Box<Trait>>, or Vec<&Trait>.
Jente Van Heuverswyn
@JenteVH
Nov 12 2017 17:06
for games it's usually possible to move a lot of things from code into data.
what do you mean with this?
Will
@tavurth
Nov 12 2017 17:07
@matklad If I used Vec<&Trait> the compiler complains about required lifetimes. I'm trying to generalise a Quadtree while hanging on to the original objects.
24 |     animals: Vec<&T>
   |                  ^ expected lifetime parameter
You can't store elements of different types in a vector.
Aleksey Kladov
@matklad
Nov 12 2017 17:10
@JenteVH here's one example from rust fest: https://youtu.be/nXR8f4r6ggM?t=19m40s. These animations are described in config files (TOML I think), and there's an editor to modify them at runtime, which gives much better iteration time if we compare it with hard-coding animations.
Will
@tavurth
Nov 12 2017 17:10
@matklad Wow, that's working, so you replaced the abstract &'a T with &'a Animal
red75prime
@red75prime
Nov 12 2017 17:11
Yes, trait object behind a reference.
Jente Van Heuverswyn
@JenteVH
Nov 12 2017 17:11
@matklad Will check it out, thanks
Will
@tavurth
Nov 12 2017 17:11
@red75prime Oh, sorry didn't see that it was you who posted it
Thank you!
Jente Van Heuverswyn
@JenteVH
Nov 12 2017 17:12
@matklad Will check it out, thanks
Will
@tavurth
Nov 12 2017 17:20
@red75prime Amazing, that's fixed it! Thank you!
QuadTree {
    depth: 7,
    max_depth: 32,
    bounds: Bounds {
        x: 48,
        y: 48,
        w: 4,
        h: 4
    },
    elements: [
        Rect {
            x: 50,
            y: 50,
            x2: 55,
            y2: 55
        },
        Square {
            x: 50,
            y: 50,
            w: 5,
            h: 5
        }
    ],
    children: None
},
Aleksey Kladov
@matklad
Nov 12 2017 17:20
@JenteVH in general though, "interactivity" when developing in Rust is pretty bad at the moment, due to huge compile times :( Things are improving though!
Akritrime
@akritrime
Nov 12 2017 18:01
Ignoring the futures stuff, is their benefit to using tokio_core's net module compared to mio's net module?