pub struct Asset<T: AssetTrait> {
pub id: AssetId<T>,
pub path: Vec<String>,
pub data: T,
}Expand description
An asset with its id. Serialized as such for the wire; files on disk use
AssetOnDisk, which takes the id from the file name.
Fields§
§id: AssetId<T>§path: Vec<String>§data: TImplementations§
Source§impl<T: AssetTrait> Asset<T>
impl<T: AssetTrait> Asset<T>
pub fn new(path: Vec<String>) -> Self
Sourcepub fn copy(&self, collections: &Collections) -> Self
pub fn copy(&self, collections: &Collections) -> Self
Create a copy of an asset with a new uuid and a name no other asset in its folder has (“Name copy”, “Name copy 2”, …), so the copy shows up as its own entry in the asset tree.
pub fn get(id: AssetId<T>, collections: &Collections) -> Option<Arc<Self>>
pub fn get_asset_from_index( index: usize, collections: &Collections, ) -> Option<Arc<Self>>
pub fn all(collections: &Collections) -> Vec<Arc<Asset<T>>>
Sourcepub fn read(reader: impl Read, id: AssetId<T>) -> Result<Arc<Self>, ReadError>
pub fn read(reader: impl Read, id: AssetId<T>) -> Result<Arc<Self>, ReadError>
Reads an asset from its JSON file. Older versions read as far as serde
takes them; migrating them is gled-migrate’s, before loading.
A file whose name is empty is named after its id, the name of the
file it came from, in the top folder. Its content stays reachable and
everything that refers to it by id keeps working; the user can rename
it, and the next save writes the name.
pub fn into_json(self) -> Result<String, Error>
Sourcepub fn dir(&self) -> Vec<String>
pub fn dir(&self) -> Vec<String>
The folders the asset is in: its path without its own name. An asset without a path (one built in code or received over the wire; files get a name when read) is in the top folder.
pub fn name(&self) -> &str
pub fn change_dir(&mut self, new_dir: &[String])
Trait Implementations§
Source§impl<T: AssetTrait> Default for Asset<T>
impl<T: AssetTrait> Default for Asset<T>
Source§impl<'de, T> Deserialize<'de> for Asset<T>
impl<'de, T> Deserialize<'de> for Asset<T>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl<T: Eq + AssetTrait> Eq for Asset<T>
impl<T: PartialEq + AssetTrait> StructuralPartialEq for Asset<T>
Auto Trait Implementations§
impl<T> Freeze for Asset<T>
impl<T> RefUnwindSafe for Asset<T>
impl<T> Send for Asset<T>
impl<T> Sync for Asset<T>
impl<T> Unpin for Asset<T>
impl<T> UnsafeUnpin for Asset<T>
impl<T> UnwindSafe for Asset<T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DebugAny for T
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more