Skip to content

Instantly share code, notes, and snippets.

@SiegeLord
Last active December 16, 2015 05:29
Show Gist options
  • Save SiegeLord/5385056 to your computer and use it in GitHub Desktop.
Save SiegeLord/5385056 to your computer and use it in GitHub Desktop.
Resource manager
struct Resource;
struct Manager<'self>
{
Resources : ~[~Resource],
Count : &'self mut i32
}
struct Object<'self>
{
Data : &'self Resource
}
fn CreateObject<'l>(manager : &'l Manager) -> Object<'l>
{
*(manager.Count) += 1;
Object{Data : &'l *manager.Resources[*manager.Count - 1]}
}
fn main()
{
let mut count : ~i32 = ~0i32;
let manager = Manager{Resources : ~[~Resource], Count : &mut *count};
let _obj1 = CreateObject(&manager);
let _obj2 = CreateObject(&manager);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment