Test to understand how to refer to things sharing a lifetime.

This commit is contained in:
2023-02-15 20:57:03 -08:00
commit 5355b4388e
4 changed files with 49 additions and 0 deletions

33
src/main.rs Normal file
View File

@@ -0,0 +1,33 @@
use std::collections::HashMap;
trait Material {}
struct Impl1 {}
impl Material for Impl1 {}
trait Shape {}
struct Impl2<M: Material> {
v: M,
}
impl<M> Shape for Impl2<M> where M: Material {}
impl Material for &Box<dyn Material> {}
struct State {
materials: HashMap<String, Box<dyn Material>>,
shape: Box<dyn Shape>,
}
fn load_map() -> State {
let mut materials: HashMap<String, Box<dyn Material>> = HashMap::new();
materials.insert("one".to_string(), Box::new(Impl1 {}));
materials.insert("two".to_string(), Box::new(Impl1 {}));
let shape = Box::new(Impl2 {
v: materials.get("one").unwrap(),
});
State { materials, shape }
}
fn main() {
let _ = load_map();
}