These are chat archives for rust-lang/rust

23rd
Sep 2018
Rotem Yaari
@vmalloc
Sep 23 2018 05:41
Hi, is there some idomatic way to sort a Vec of Option<u64>, having Nones appear first in the final result?
Zakarum
@omni-viral
Sep 23 2018 07:35
@vmalloc like this myvec.sort()
None is smaller than Some(x)
Rotem Yaari
@vmalloc
Sep 23 2018 07:42
@omni-viral Doh (slaps forehead). Thanks!
Kelly Thomas Kline
@kellytk
Sep 23 2018 08:04
I would like one of the dependencies of my app to be a locally developed lib which is not on crates.io. Is it sufficient to declare its Cargo.toml entry with path="./local/repo/path" or should I use patch as well?
Zakarum
@omni-viral
Sep 23 2018 08:05
path="./local/repo/path" is enough
Michal 'vorner' Vaner
@vorner
Sep 23 2018 08:05
It should be enough (well, you're going to have trouble if you move things around, so you might be better with workspaces unless you share the lib). You need patch to replace dependencies of your dependencies.
Zakarum
@omni-viral
Sep 23 2018 08:06
However without version you can't publish your own crate
Kelly Thomas Kline
@kellytk
Sep 23 2018 09:20
There's a facet of complexity I should mention, locally the repo is at a given path but the code is built on a remote machine and when built the repo will be at a different path. How should that be handled?
Zakarum
@omni-viral
Sep 23 2018 09:38
Simplify complexity. Make paths equal. Use the power of symlinks maybe
Kelly Thomas Kline
@kellytk
Sep 23 2018 12:49
Thank you
Michal 'vorner' Vaner
@vorner
Sep 23 2018 15:00
I'm trying out the 2018 edition. How do I use a macro from parent module?
Ah, right, I don't, they leak into the module automatically, but only if they are declared above the mod submodule. That's… surprising.
Denis Lisov
@tanriol
Sep 23 2018 16:09
That's the original behavior from since 1.0, IIRC.
Michal 'vorner' Vaner
@vorner
Sep 23 2018 16:13
That was somewhat consistent with the #[macro_use], but I expected them to act similar to other items when they are now imported with use or can write some_crate::macro!.
Michael(LAI)
@Michael-Lfx
Sep 23 2018 16:45
Is lifetime parameter used for borrow type only? If I create a ResourcePool<T> and create all the instance of T from it, ResourcePool<T> itself does not required any lifetime parameter in its definition, is that right? I want to achieve a goal that only the holder of a instance of ResourcePool<T> be freed then ResourcePoolshould be freed and frees its objects before it vanish .Here is the code snippet.
pub struct ResourcePool<T> {
    counter: u32,
    objects: BTreeMap<u32, T>,
}
pub struct ResourceManager {
    shaders:  ResourcePool<Shader>,
    textures: ResourcePool<Texture>,
    buffers:  ResourcePool<Buffer>,
    // ...
}
D'Silva
@evnix
Sep 23 2018 19:52
what is the standard way of concatenating strings?
let a: String = "John";
let b: String = "Smith";
let c = a+b // doesn't seem to work, I did search and I found some crazy things like using format! and joins
what would be the standard way of doing a simple concat operation?
D'Silva
@evnix
Sep 23 2018 19:58
I see, Thanks
Timothy Shoaf
@timshoaf
Sep 23 2018 19:58
np :)
Timothy Shoaf
@timshoaf
Sep 23 2018 21:29
Is it the common pattern here to implement the From trait between error types when using various libraries that define their own errors to allow for method chaining via ? or is there a more idiosyncratic design pattern people use for error translation?
Urjit Singh Bhatia
@urjitbhatia
Sep 23 2018 23:50

I have a rust noob question:

  • I am sharing a data structure among threads using Arc and a Mutex
let hub_mutex_rc = Arc::new(Mutex::new(Hub::new(10_000)));
let hub_producer = Arc::clone(&hub_mutex_rc);
let max_jobs = conf.count.unwrap_or(50);

println!("starting producer thread");
let producer_thread = thread::Builder::new()
    .name("producer".into())
    .spawn(move || {
        let client = Client::new("127.0.0.1:8125", "yaad.").unwrap();
        for job_counter in 0..max_jobs {
            let j = Job::new_auto_id(times::current_time_ms());
            client.time("foo", || {
                let mut h = hub_producer.lock().unwrap();
                h.add_job(j);
            });
        }
    }).unwrap();

The client is a statsd client from : https://docs.rs/statsd/0.11.0/statsd/client/struct.Client.html#method.timer
I am getting this error:
h.add_job(j); cannot move out of captured outer variable in an `Fn` closure

I need to do other stuff on j before giving it to the timer client. How can I fix this? thanks!