[rust-dev] Lifetime help
adamson.benjamin at gmail.com
Sun Jan 19 17:28:40 PST 2014
I having a little trouble resolving this issue on my own, and I think it's
an issue of syntax, not so much comprehending life times.
What I'm doing is, using the RSFML library to try and write a pong clone in
rust. So far it's been going awesome! I'm running into a small problem with
lifetimes though. To give some context, SFML separates textures from
sprites, and sprites can be created with a borrowed pointer to a texture. I
first load all the textures into a HashMap, and pass that hashmap to a
function which (is supposed to) will return a HashMap of Sprites. These
sprites I would like to initialize inside the function with references to
the textures in the input HashMap of textures.
Based on my understanding of borrowed pointers, this should be able to
work. In fact, I wrote a simpler version of my function just to make sure I
understand what I am not understanding. I wrote a version of the function
which takes the same HashMap of textures, and returns a single sprite (not
a hashmap). The single sprite is created with a reference to the first
texture in the hashmap. I was able to figure out the syntax to express
this. However I can't seem to figure out the syntax for the more
complicated case, returning the hashmap of Sprites.
I created a gist for easy viewing of the code I am having trouble with, and
I think I've made it very obvious what's happening in the gist link,
hopefully somebody can help me sort this out :D
also the link to the full file, if it helps.
Thanks in advance!!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Rust-dev