Skip to main content

pebble/assets/
handle.rs

1use crate::assets::storage::RawAssetHandle;
2
3/// A typed wrapper around a [`RawAssetHandle`].
4///
5/// `Handle<T>` is cheap to copy and store. It does not keep the underlying
6/// asset alive — the asset lives in [`Assets<T::Source>`](crate::assets::storage::Assets)
7/// and can be removed independently.
8pub struct Handle<T> {
9    pub id: RawAssetHandle,
10    _marker: std::marker::PhantomData<T>,
11}
12
13impl<T> Handle<T> {
14    /// Create a new typed handle from a raw slot-map key.
15    pub fn new(id: RawAssetHandle) -> Self {
16        Self {
17            id,
18            _marker: std::marker::PhantomData,
19        }
20    }
21}
22impl<T> Clone for Handle<T> {
23    fn clone(&self) -> Self {
24        *self
25    }
26}
27impl<T> Copy for Handle<T> {}