pub struct AssetIndex {
pub version: u32,
pub assets: HashMap<String, CachedAsset>,
}Expand description
In-memory representation of the index.json file.
Fields§
§version: u32Schema version.
assets: HashMap<String, CachedAsset>All known assets keyed by id.
Implementations§
Source§impl AssetIndex
impl AssetIndex
Sourcepub fn load(cache_dir: &Path) -> Result<Self>
pub fn load(cache_dir: &Path) -> Result<Self>
Load the index from cache_dir/index.json, returning an empty index
if the file does not exist.
If the file exists but cannot be parsed (or has a version mismatch),
an empty index is returned and all non-index files under
cache_dir are purged so that blobs that are no longer tracked by
the index cannot accumulate indefinitely on disk.
Sourcepub fn save(&self, cache_dir: &Path) -> Result<()>
pub fn save(&self, cache_dir: &Path) -> Result<()>
Persist the index to cache_dir/index.json atomically via
temp file + rename.
Sourcepub fn upsert(&mut self, asset: CachedAsset)
pub fn upsert(&mut self, asset: CachedAsset)
Insert or replace an asset entry.
Sourcepub fn remove(&mut self, id: &str) -> Option<CachedAsset>
pub fn remove(&mut self, id: &str) -> Option<CachedAsset>
Remove an asset entry, returning the old value if any.
Sourcepub fn get(&self, id: &str) -> Option<&CachedAsset>
pub fn get(&self, id: &str) -> Option<&CachedAsset>
Look up an asset by id.
Sourcepub fn get_mut(&mut self, id: &str) -> Option<&mut CachedAsset>
pub fn get_mut(&mut self, id: &str) -> Option<&mut CachedAsset>
Mutably look up an asset by id.
Sourcepub fn total_size(&self) -> u64
pub fn total_size(&self) -> u64
Total size in bytes of all tracked assets.
Trait Implementations§
Source§impl Clone for AssetIndex
impl Clone for AssetIndex
Source§fn clone(&self) -> AssetIndex
fn clone(&self) -> AssetIndex
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for AssetIndex
impl Debug for AssetIndex
Source§impl Default for AssetIndex
impl Default for AssetIndex
Source§impl<'de> Deserialize<'de> for AssetIndex
impl<'de> Deserialize<'de> for AssetIndex
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for AssetIndex
impl RefUnwindSafe for AssetIndex
impl Send for AssetIndex
impl Sync for AssetIndex
impl Unpin for AssetIndex
impl UnsafeUnpin for AssetIndex
impl UnwindSafe for AssetIndex
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