Yes, using keys (or indices into a vector) is an option. There are two problems with this.
It is pretty inefficient; one has to access the pool at any point, which means doubling the sizes of the pointers (at least), probably more; One needs a lot of unsafe code to allow mutating the pools; And there's the issue of keeping multiple pools (one per type)... So it gets complex fast, though perhaps a "sufficiently smart library" could still do a good job? On Mon, Nov 4, 2013 at 8:18 AM, Daniel Micay <[email protected]> wrote: > On Mon, Nov 4, 2013 at 1:11 AM, Oren Ben-Kiki <[email protected]> wrote: > >> I am toying with a non-trivial Rust project to get a feel for the >> language. There's a pattern I keep seeing in my code which isn't easy to >> express in Rust. I wonder what the "right thing to do" is here. >> >> The pattern is as follows. I have some container, which contains some >> components of different types. The container as a whole is send-able . The >> components form a complex graph (with cycles). >> > > If there are keys, the path of least resistance is to use a map or a pair > of maps. Reference counting can allow cyclic links in data structures as > long as the ownership graph is acyclic, but Rust doesn't offer a type like > this at the moment. >
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
