#[repr(transparent)]pub struct AssetId(pub NonZeroU64);Expand description
Type for unique asset identification. There are 2^64-1 valid values of this type that should be enough for now.
Using NonZero makes Option<AssetId> same size as AssetId which is good for performance.
Tuple Fields§
§0: NonZeroU64Implementations§
Source§impl AssetId
impl AssetId
Sourcepub const fn new(value: u64) -> Option<Self>
pub const fn new(value: u64) -> Option<Self>
Examples found in repository?
examples/proc.rs (line 128)
123async fn run() -> Result<(), Box<dyn std::error::Error>> {
124 // Fill map.
125 let source = HashMapSource(
126 vec![
127 (
128 AssetId::new(2).unwrap(),
129 b"null".to_vec().into_boxed_slice(),
130 ),
131 (
132 AssetId::new(3).unwrap(),
133 b"{\"field\": {}}".to_vec().into_boxed_slice(),
134 ),
135 (
136 AssetId::new(4).unwrap(),
137 b"{\"a\": 3}".to_vec().into_boxed_slice(),
138 ),
139 (
140 AssetId::new(5).unwrap(),
141 b"{\"c\": {\"a\": 2}, \"a\": 3}".to_vec().into_boxed_slice(),
142 ),
143 (
144 AssetId::new(6).unwrap(),
145 b"{\"wrapped\": 42}".to_vec().into_boxed_slice(),
146 ),
147 (
148 AssetId::new(7).unwrap(),
149 b"{\"a\": 6}".to_vec().into_boxed_slice(),
150 ),
151 (AssetId::new(8).unwrap(), b"{}".to_vec().into_boxed_slice()),
152 ]
153 .into_iter()
154 .collect(),
155 );
156
157 let loader = Loader::builder().with(source).build();
158
159 let _: &UnitAsset = loader.load("2").await.build(&mut ())?;
160 println!("UnitAsset loaded");
161
162 let _: &SimpleAsset = loader.load("3").await.build(&mut ())?;
163 println!("SimpleAsset loaded");
164
165 let _: &TwoLevelAsset = loader.load("4").await.build(&mut ())?;
166 println!("TwoLevelAsset loaded");
167
168 let _: &ComplexAsset = loader.load("5").await.build(&mut ())?;
169 println!("ComplexAsset loaded");
170
171 let _: &WrapperAsset = loader.load("6").await.build(&mut ())?;
172 println!("WrapperAsset loaded");
173
174 let _: &AssetWithWrapper = loader.load("7").await.build(&mut ())?;
175 println!("AssetWithWrapper loaded");
176
177 let _: &AssetWithSerdeAttribute = loader.load("8").await.build(&mut ())?;
178 println!("AssetWithSerdeAttribute loaded");
179
180 let _: &AssetWithOption = loader.load("8").await.build(&mut ())?;
181 println!("AssetWithOption loaded");
182
183 Ok(())
184}Trait Implementations§
Source§impl<A> Borrow<AssetId> for TypedAssetId<A>
impl<A> Borrow<AssetId> for TypedAssetId<A>
impl Copy for AssetId
Source§impl<'de> Deserialize<'de> for AssetId
impl<'de> Deserialize<'de> for AssetId
Source§fn deserialize<D>(deserializer: D) -> Result<AssetId, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<AssetId, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for AssetId
Source§impl Ord for AssetId
impl Ord for AssetId
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for AssetId
impl PartialOrd for AssetId
impl StructuralPartialEq for AssetId
Auto Trait Implementations§
impl Freeze for AssetId
impl RefUnwindSafe for AssetId
impl Send for AssetId
impl Sync for AssetId
impl Unpin for AssetId
impl UnsafeUnpin for AssetId
impl UnwindSafe for AssetId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more