use std::{ any::{type_name, Any}, error::Error, }; /// Bound on the types that can be used as an aerosol resource. pub trait Resource: Any + Send + Sync + Clone {} impl Resource for T {} pub(crate) fn unwrap_resource(opt: Option) -> T { if let Some(value) = opt { value } else { panic!("Resource `{}` does not exist", type_name::()) } } pub(crate) fn unwrap_constructed(res: Result) -> T { match res { Ok(x) => x, Err(e) => panic!("Failed to construct `{}`: {}", type_name::(), e), } } pub(crate) fn duplicate_resource() -> ! { panic!( "Duplicate resource: attempted to add a second `{}`", type_name::() ) } pub(crate) fn cyclic_resource() -> ! { panic!( "Cycle detected when constructing resource `{}`", type_name::() ) }