Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created November 8, 2019 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/348ea8d489773fcd46ccd25c39683d5f to your computer and use it in GitHub Desktop.
Save rust-play/348ea8d489773fcd46ccd25c39683d5f to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
struct Model {
pub data: Box<[u8]>
}
struct Entity {
// ...
pub model_idx: usize
}
struct World {
entities: Vec<Entity>,
models: Vec<Model>
}
fn main() {
let model = Model { data: vec![1,2,3].into_boxed_slice() };
let entity = Entity { model_idx: 0 };
let world = World {
entities: vec![entity],
models: vec![model]
};
println!("{:?}", world.models[world.entities[0].model_idx].data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment