fast-assets
Easy to use assets manager for Rust
⚠️ Warning ⚠️
This library is still under development, shared to get feedbacks. If you found a missing feature open an issue on github. All unchecked features are planned.
Features
- Search for files
- Index files
- Load assets
- Load compressed assets
- Write files (not compressed only)
- Dependencie Checker
Compression Support
- ZIP (.zip)
Load pre-defined index
Used to load files compressed
- From CSV file
Example
let mut index = new;
index.add_from_file;
index.set_csv_separator;
folder/subfolder/file.txt
archives/archive.zip/file.txt
Getting Started
Initialization
// Search all un-compressed files and archives,
// using extern index allow to add files compressed,
// the manager will automatically manage the decompression
let mut index = new;
index.search;
index.add_from_file;
// The decompression cache is what will manage your compressed files and their caches.
let dc = default;
let mut manager = new;
Loading/Unloading a file in memory
// Load a compressed file
manager.load.unwrap;
// Load a not compressed file
manager.load.unwrap;
// Load a not compressed file using full path
manager.load.unwrap;
// Load a compressed file using full path
manager.load.unwrap;
// AssetsManager::unload() need two parameters:
// decompression_cache: bool => If the file was compressed and if true it will put the file in the cache.
// filename: &str => The file that will be unloaded
// UnLoad and put in cache a compressed file
manager.unload;
// UnLoad a not compressed file
manager.unload;
// Tips: if you want always keep in cache, set always at true,
// it will have no impact on the unloading of a uncompressed file
Accessing Data
You must know that two thing can failed:
- File not indexed
- File not exists
So you need to passthrough them to access the data:
manager.get.unwrap.unwrap;
manager.get_ref.unwrap.unwrap;
manager.get_mut.unwrap.unwrap;
// In the case where you have multiple file with the same name:
// When not compressed
manager.get.unwrap;
manager.get_ref.unwrap;
manager.get_mut.unwrap;
// When compressed (relative to the compressed directory)
manager.get.unwrap;
manager.get_ref.unwrap;
manager.get_mut.unwrap;
If the file was put in cache it will automatically reload it.
Saving Data
⚠️ This features encounters io authorizations issues ⚠️
Only saves data of file that are not from compressed files. Return a simple std::io::Result<()> as result. If the file does not exist anymore it will create a new file.
manager.save.unwrap;
Remove a file reference
In the manager and DecompressionCache each file loaded will have his reference, but them use memory, so to do a complete unload you need to remove them. For the cached files, they will have their cache file removed (based on the trait Drop).
manager.remove.unwrap.unwrap;
// Tips: You don't need to unload before excepted if you need to put in cache