Re: [rust-dev] Storing Handle (for Select) in a collection causes a crash

2014-04-16 Thread Alex Crichton
> unsafe { h.add(); } > > handles.insert(h.id(), h); This is why the add method is unsafe: "This method is unsafe because it requires that the Handle is not moved while it is added to the Select set." You're moving the handle after it's been added, which later will cause a segfault. _

Re: [rust-dev] Storing Handle (for Select) in a collection causes a crash

2014-04-16 Thread Frank Huang
Ah, yes I failed to see the warning in the documentation. add()ing the handle after moving it into the hashmap does seem to make things better. Thanks for your help! Frank On Wed, Apr 16, 2014 at 5:45 PM, Alex Crichton wrote: > > unsafe { h.add(); } > > > > handles.insert(h.id(), h); > > T

Re: [rust-dev] Storing Handle (for Select) in a collection causes a crash

2014-04-16 Thread Patrick Walton
On 4/16/14 5:39 PM, Frank Huang wrote: Second somewhat related question: why can't I write this? fn main() { let mut v = Vec::new(); v.push(10); // get last item let n = v.get_mut(v.len()-1); println!("item = {}", *n); } For this program, the compiler complains at the line with v

[rust-dev] Storing Handle (for Select) in a collection causes a crash

2014-04-16 Thread Frank Huang
Hello all, I have two somewhat related questions to ask you fine folks. I'm trying to implement something that selects on a variable number of receivers, which can change during program execution. I've been attempting to do so by making Handles to those receivers and storing the handles in a HashM