These are chat archives for rust-lang/rust

29th
Sep 2018
Paul Hauner
@paulhauner
Sep 29 2018 02:01
My binary compliles on stable however I have some benches (using unstable test) which is presently forcing me to always compile on nightly. I'd like to have the option to compile on stable w/o benches or compile on nightly w/ benches. My first thought was to place an unstable feature (e.g., #![feature(test)] "behind" another feature (e.g., #[feature(my_benches)], but I can't seem to get that to work. Does anyone know how I might go about achieving this please? (Ideally I'd like to avoid having two separate branches; one for stable and one for nightly)
bspeice
@bspeice
Sep 29 2018 02:17
Dang, came here with a similar issue I'm hoping to solve. Is it possible to conditionally compile for no_std?
bspeice
@bspeice
Sep 29 2018 02:34
Finally got the no_std stuff working:
#![cfg(feature = "my_feature")] #![no_std]
@paulhauner - You can't have #![feature()] following #[feature()]. Not sure how to gate features on each other though.
David Vo
@auscompgeek
Sep 29 2018 02:36
don't you want cfg_attr?
bspeice
@bspeice
Sep 29 2018 02:41
Ooh, thanks. And with luck, rust-lang/rfcs#2539 will land soon.
Paul Hauner
@paulhauner
Sep 29 2018 03:04
That didn't work for me, but thanks for the thought @bspeice
trsh
@trsh
Sep 29 2018 06:03
A Future can return something like err or ok, but is there something I can make the process wait
?
Like do something repeatedly (check for smth), and return ready or err only when it's time
trsh
@trsh
Sep 29 2018 07:28
I like loop_fn, but duno how to set delays for loops
Serak Shiferaw
@serak
Sep 29 2018 07:58
Hi Everyone
i am new to rust and i still could not figure out a dynamic link in cargo , everytime i add a dependency in cargo toml its statically compiled to one exe and i don't want that
Serak Shiferaw
@serak
Sep 29 2018 08:39
like output regex.rlib,clib.rlib,mainApp.exe ->from one cargo project
Denis Lisov
@tanriol
Sep 29 2018 09:08
@serak The problem is that significant parts of these libraries would be compiled into the exe anyway (basically, generic types and everything that has type parameters).
trsh
@trsh
Sep 29 2018 09:26
Anybody has ideas how to use futures Timeout?
let client = Client::new();
    let sp = client.send_ping();

    let handle_conn = sp.map(|amt| {
      println!("dddddddddddd = {:?}", amt.ping_count);
    }).map_err(|err| {
      println!("dddddddddddd2 = {:?}", err);
    });

    handle.spawn(handle_conn);

    println!("Timer setup");

    let kaka = Timeout::new(Duration::new(30, 0), &handle).and_then(|a| {
      println!("Some timeout shit appened = {:?}", a);

      Ok(())
    });

    println!("kaka = {:?}", kaka);
For me 1) Handle conn never happends, 2) There is no 30 sec delay for "Some timeout s* ...."
Serak Shiferaw
@serak
Sep 29 2018 09:28
@tanriol what is i want to reuse 1 library for a set of executable application. ? building everything in one exe makes is large if you are creating a lot of them specially utilities like grep ping ssh ....
trsh
@trsh
Sep 29 2018 09:51
println!("Timer setup");

    let now = Instant::now() + Duration::new(100, 0);
    let kaka = Timeout::new_at(now, &handle).and_then(|a| {
      println!("Some timeout shit appened = {:?}", a);
      Ok(())
    });

    println!("kaka = {:?}", kaka);

    kaka.and_then(|_|{
      Ok(println!("Jaja"))
    });
Again, everything happens instantly, not timeouts, as docs says
trsh
@trsh
Sep 29 2018 09:56
Anybody exp with this?
Paul Hauner
@paulhauner
Sep 29 2018 10:04
I’m on my phone so I can’t troubleshoot, but try the “tokio” library. It has docs and it works.
If you are already using tokio, you need to use the “run” function to execute your futures.
trsh
@trsh
Sep 29 2018 10:08
Execution is not the problem
Can't find any usefull examples
Torben Jonas
@TorbenJ
Sep 29 2018 11:22

From https://doc.rust-lang.org/std/vec/struct.Vec.html

In Rust, it's more common to pass slices as arguments rather than vectors when you just want to provide a read access.

I'm just learning Rust and as there is no further explanation on why this is more common I have to guess: Is it because slices are more generic or are there any other advantages?

Lyle Mantooth
@IslandUsurper
Sep 29 2018 12:03
@TorbenJ, slices are more generic. Slices can come from fixed-length arrays, Vecs, or Strings (which are just fancy Vec<u8> to maintain UTF-8 encoding).
Also, slices can be just part of those things, where a &Vec gives a reference to the whole thing. For example &foo[0..1] is a slice containing the first two elements, though foo may have lots more.
But you can still pass a &Vec to a function that wants a slice because . . . of a particular trait I can't remember the name of. AsRef maybe?
Deref?
IslandUsurper @IslandUsurper shrugs
Torben Jonas
@TorbenJ
Sep 29 2018 12:09
@IslandUsurper thanks, so my guess was kind of correct but I forgot about the thing that slices might be just a part of the original collection :)
Lyle Mantooth
@IslandUsurper
Sep 29 2018 12:11
Yeah, I think the fact that slices are generic isn't as important. I don't see arrays used a whole lot, and sub-slices of arrays probably never.
trsh
@trsh
Sep 29 2018 14:19
Hey im installing this lib https://github.com/TheNeikos/rustbreak, and getting on build > deserialize is ambiguous
Could it be some conflict with Serde json
error[E0659]: `deserialize` is ambiguous
   --> /home/trsh/.cargo/registry/src/github.com-1ecc6299db9ec823/rustbreak-1.4.0/src/lib.rs:156:13
    |
156 |         use enc::deserialize;
    |             ^^^^^^^^^^^^^^^^
    |
note: `deserialize` could refer to the name imported here
   --> /home/trsh/.cargo/registry/src/github.com-1ecc6299db9ec823/rustbreak-1.4.0/src/lib.rs:80:37
    |
80  |     #[cfg(feature = "bin")] pub use bincode_enc::*;
    |                                     ^^^^^^^^^^^^^^
note: `deserialize` could also refer to the name imported here
   --> /home/trsh/.cargo/registry/src/github.com-1ecc6299db9ec823/rustbreak-1.4.0/src/lib.rs:82:41
    |
82  |     #[cfg(feature = "ron_enc")] pub use ron_enc::*;
    |                                         ^^^^^^^^^^
    = note: consider adding an explicit import of `deserialize` to disambiguate
Any ideas? Report an bug?
Lyle Mantooth
@IslandUsurper
Sep 29 2018 14:42
@trsh, the error says two different deserialize exist in rustbreak. But they're feature gated, so maybe you should only use one of bin and ron_enc.
trsh
@trsh
Sep 29 2018 14:50
default-features = false
Was the key
or its both and then this..
Lyle Mantooth
@IslandUsurper
Sep 29 2018 15:17
Then its README is doubly wrong, since it specifies bin_enc instead of bin like in the code you have.
Ah, I was looking at master, not v1.4.
Yes, for 1.4, you'd have to specify default-features = false and set the feature you want if it's not bin.
tandrysyawaludin
@tandrysyawaludin
Sep 29 2018 18:41
Do anyone know?
62 |     const encoded_password: String =  || {make_password(&new_supplier.password)};
   |                                                          ^^^^^^^^^^^^
   |
   = help: use the `|| { ... }` closure form instead
Wil Hunt
@huntwj
Sep 29 2018 21:03

I’ve not seen that error, but it looks like you’re trying to assign a closure to a String variable. What happens when you simplify it to

const encoded_password: String = make_password(&new_supplier.password);

If that doesn’t work, we may need more context such as where/what new_supplier is, type wise, and what the signature of make_password is.