MCPcopy Index your code
hub / github.com/a1phyr/assets_manager

github.com/a1phyr/assets_manager @v0.13.9

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.13.9 ↗ · + Follow
550 symbols 1,130 edges 40 files 69 documented · 13%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Assets-manager

Crates.io Docs.rs

This crate aims at providing a filesystem abstraction to easily load external resources. It was originally thought for games, but can of course be used in other contexts.

Original idea was inspired by Veloren's assets system.

This crate follow semver convention and supports rustc 1.85 and higher. Changing this is considered a breaking change.

Goals

This crates focuses on:

  • Good performances:\ Crucial for perfomance-oriented applications such as games.\ Loaded assets are cached so loading one several times is as fast as loading it once. This crate was thought for use with concurrency.

  • Hot-reloading:\ Hot-reloading means updating assets in memory as soon as the corresponding file is changed, without restarting your program. It may greatly ease development.\ Your time is precious, and first-class support of hot-reloading helps you saving it.

  • Pleasant to use:\ A well-documented high-level API, easy to learn.\ Built-in support of common formats: serialization, images, sounds.\ Can load assets from a file system, a zip archive, or even embed them in a binary.

  • Lightness:\ Pay for what you take, no dependency bloat.

Example

Suppose that you have a file assets/common/position.ron containing this:

Point(
    x: 5,
    y: -6,
)

Then you can load it this way (with feature ron enabled):

use assets_manager::{Asset, AssetCache};
use serde::Deserialize;

// The struct you want to load
// This example uses a derive macro, but assets can be customized at will.
#[derive(Deserialize, Asset)]
#[asset_format = "ron"]
struct Point {
    x: i32,
    y: i32,
}

// Create a new cache to load assets under the "./assets" folder
let cache = AssetCache::new("assets")?;

// Get a handle on the asset
// This will load the file `./assets/common/position.ron`
let handle = cache.load::<Point>("common.position")?;

// Lock the asset for reading
// Any number of read locks can exist at the same time,
// but none can exist when the asset is reloaded
let point = handle.read();

// The asset is now ready to be used
assert_eq!(point.x, 5);
assert_eq!(point.y, -6);

// Loading the same asset retrieves it from the cache
let other_handle = cache.load("common.position")?;
assert!(std::ptr::eq(handle, other_handle));

Hot-reloading is also very easy to use:

let cache = AssetCache::new("assets")?;
let handle = cache.load::<Point>("common.position")?;

loop {
    // Assets are updated without any further work
    println!("Current value: {:?}", handle.read());
}

License

Licensed under either of

  • Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Extension points exported contracts — how you extend this code

FileAsset (Interface)
An asset that can be loaded from a single file. Implementing this trait provides an implementation of [`Asset`]. [10 implementers]
src/asset.rs
Source (Interface)
Bytes sources to load assets from. This trait provides an abstraction over filesystem operations, allowing assets to be [10 …
src/source/mod.rs
DirLoadable (Interface)
Assets that are loadable from directories Types that implement this trait can be used with [`AssetCache::load_dir`] to [5 …
src/dirs.rs
Asset (Interface)
An asset type that can load other kinds of assets. `Asset`s can be loaded and retrieved by an [`AssetCache`]. Note tha [12 …
src/asset.rs
ReadSeek (Interface)
(no doc) [1 implementers]
src/source/zip.rs
Storable (Interface)
Trait marker to store values in a cache. This is the set of types that can be stored in a cache. [1 implementers]
src/asset.rs
BufReadSeek (Interface)
(no doc) [1 implementers]
src/source/zip.rs
Compound (Interface)
(no doc) [1 implementers]
src/asset.rs

Core symbols most depended-on inside this repo

as_ref
called by 29
src/source/mod.rs
iter
called by 21
src/map.rs
clone
called by 19
src/entry.rs
map
called by 18
src/entry.rs
get
called by 18
src/utils/cell.rs
clone
called by 16
src/utils/bytes.rs
read
called by 15
src/entry.rs
push
called by 15
src/utils/private.rs

Shape

Method 342
Function 95
Class 90
Enum 14
Interface 9

Languages

Rust100%

Modules by API surface

src/entry.rs56 symbols
src/cache.rs48 symbols
src/source/zip.rs33 symbols
src/utils/bytes.rs28 symbols
src/source/tar.rs28 symbols
src/source/mod.rs28 symbols
src/utils/private.rs27 symbols
src/utils/string.rs23 symbols
src/tests.rs20 symbols
src/utils/cell.rs18 symbols
src/hot_reloading/records.rs16 symbols
macros/src/embedded.rs16 symbols

For agents

$ claude mcp add assets_manager \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact