use {Resource, Resources};
#[cfg(feature = "nightly")]
macro_rules! fetch_panic {
() => {{
panic!(
"Tried to fetch a resource of type {:?}, but the resource does not exist.\n\
Try adding the resource by inserting it manually or using the `setup` method.",
unsafe { ::std::intrinsics::type_name::<T>() },
)
}};
}
#[cfg(not(feature = "nightly"))]
macro_rules! fetch_panic {
() => {{
panic!(
"Tried to fetch a resource, but the resource does not exist.\n\
Try adding the resource by inserting it manually or using the `setup` method.\n\
You can get the type name of the missing resource by enabling `shred`'s `nightly` \
feature"
)
}};
}
pub struct DefaultProvider;
impl<T> SetupHandler<T> for DefaultProvider
where
T: Default + Resource,
{
fn setup(res: &mut Resources) {
res.entry().or_insert_with(T::default);
}
}
pub trait SetupHandler<T>: Sized {
fn setup(res: &mut Resources);
}
pub struct PanicHandler;
impl<T> SetupHandler<T> for PanicHandler
where
T: Resource,
{
fn setup(_: &mut Resources) {}
}