commit 5355b4388ea7e55b7085a3bff1e6db89456660f9 Author: Bill Thiede Date: Wed Feb 15 20:57:03 2023 -0800 Test to understand how to refer to things sharing a lifetime. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..a0e3560 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "rustrefs" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..935c18e --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rustrefs" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..036f7c9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,33 @@ +use std::collections::HashMap; + +trait Material {} +struct Impl1 {} +impl Material for Impl1 {} + +trait Shape {} +struct Impl2 { + v: M, +} +impl Shape for Impl2 where M: Material {} +impl Material for &Box {} + +struct State { + materials: HashMap>, + shape: Box, +} + +fn load_map() -> State { + let mut materials: HashMap> = 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(); +}