I solved these problems somewhat clunkily using an enum:

https://github.com/jfager/d3cap/blob/master/multicast.rs

It's not pretty but it gets the job done until the various issues around
this get worked out.



On Thursday, November 14, 2013, Diego Ongaro wrote:

> Hi all,
>
> My program starts a bunch of tasks, then I want the main task to both
> receive ctrl-c signals and receive results from the children. The
> signal will come from a std::rt::io::signal::Listener's port, which is
> an std::comm::Port<Signum>. The child results will come from a
> std::comm::Port<~[uint]>.
>
> My first problem is that std::comm::Port doesn't implement
> std::select::Select. It looks like std::rt::comm::Port does, and
> std::comm::Port is just a small wrapper around that, but
> std::comm::Port makes its internal std::rt::comm::Port private. Is
> there any way to select on a std::comm::Port? (And what's the
> difference between a std::rt::comm::Port and a std::comm::Port?)
>
> My second problem is that std::select::select() doesn't seem to
> support selecting from ports with different types. Naively, I tried
> select([p1, p2]), but that expects p1 and p2 to have the same type:
> error: mismatched types: expected
> `std::rt::comm::Port<std::rt::io::signal::Signum>` but found
> `std::rt::comm::Port<~[uint]>` (expected enum
> std::rt::io::signal::Signum but found vector)
> It'll need dynamic dispatch, so I tried: select([p1 as &Select, p2 as
> &Select]). However, this doesn't work since &Select doesn't implement
> Select:
> error: failed to find an implementation of trait std::select::Select
> for &std::select::Select<no-bounds>
>
> There's some commented out code that may be related in select.rs,
> though it's hard for me to know where this stands:
> /* FIXME(#5121, #7914) This all should be legal, but rust is not
> clever enough yet.
>
> impl <'self> Select for &'self mut Select {
>     fn optimistic_check(&mut self) -> bool { self.optimistic_check() }
>     fn block_on(&mut self, sched: &mut Scheduler, task: BlockedTask) ->
> bool {
>         self.block_on(sched, task)
>     }
>     fn unblock_from(&mut self) -> bool { self.unblock_from() }
> }
> ...
>
> How can I select on two ports of different types?
>
> Thanks,
> Diego
> _______________________________________________
> Rust-dev mailing list
> [email protected] <javascript:;>
> https://mail.mozilla.org/listinfo/rust-dev
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to