These are chat archives for rust-lang/rust

27th
Jan 2017
Kibeom Kim
@kkimdev
Jan 27 2017 18:27 UTC
Can I ask beginner questions here or is there a more appropriate place?
Alexey
@KalitaAlexey
Jan 27 2017 18:27 UTC
You can.
Kibeom Kim
@kkimdev
Jan 27 2017 18:28 UTC
I see ok!
Ivan Borgia Dardi
@ivandardi
Jan 27 2017 18:28 UTC
I'm also in the process of creating a discord server for the people that don't like either gitter or IRC
Alexey
@KalitaAlexey
Jan 27 2017 18:28 UTC
Ask here since you are already here.
Kibeom Kim
@kkimdev
Jan 27 2017 18:30 UTC
Q: I'm using RwLock and calling unwrap() here and there. Currently I'm wrapping those statements with {} like {rw_lock.write().unwrap().call_something()} to minimize the duration I hold the rw_lock. Is this correct? and is there more idiomatic way instead of using a block every time?
Alexey
@KalitaAlexey
Jan 27 2017 18:31 UTC
@kkimdev,
It is idiomatic.
If you do it too often you can write helper function.
fn do_something<F>(f: F) {
    let mut lock = rw_lock.write().unwrap();
    f(&mut lock);
}
Kibeom Kim
@kkimdev
Jan 27 2017 18:32 UTC
@KalitaAlexey I see. So If I don't use the block then, the lock remains until the next block exit? I wasn't too sure when the lock is dropped.
Alexey
@KalitaAlexey
Jan 27 2017 18:33 UTC
@kkimdev Yes, the object dropped at the end of the enclosing block.
Kibeom Kim
@kkimdev
Jan 27 2017 18:33 UTC
I see. thanks!
I vaguely remember that there was an RPC proposing dropping earlier than the enclosing block if possible. Things like lock, we would prefer to drop early, so I was thinking maybe we can have two types of Drop, the conventional one, and another one for dropping as early as possible.
Aleksey Kladov
@matklad
Jan 27 2017 18:39 UTC
@kkimdev @KalitaAlexey I always thought that temporaries are dropped after the expression is evaluated, unless they are bound to some reference...
Kibeom Kim
@kkimdev
Jan 27 2017 18:40 UTC
@matklad ok I guess I don't need the blocks thanks :)
Peter Atashian
@retep998
Jan 27 2017 18:40 UTC
If you store a temporary to a variable, it gets promoted to live for the entire block
If you don't store a temporary, then it only lives for the duration of the statement
Alexey
@KalitaAlexey
Jan 27 2017 18:41 UTC
Wow)
The more I know.
Kibeom Kim
@kkimdev
Jan 27 2017 19:02 UTC
I wanted to hear people's thoughts on early drop trait so I just shared it https://internals.rust-lang.org/t/pre-rfc-early-drop-trait/4678
Alexey
@KalitaAlexey
Jan 27 2017 19:19 UTC
@kkimdev,
@matklad said that temporaries drop early.
@kkimdev,
I don't understand your motivation, but I already hate this feature.
Just contemplate about it.
You are suggesting to change drop behavior from determined and single to varying.