Skip to main content

AssetDB

Struct AssetDB 

Source
pub struct AssetDB { /* private fields */ }

Implementations§

Source§

impl AssetDB

Source

pub fn with_backend(backend: Box<dyn StorageBackend>) -> Result<Arc<Self>>

Create a new AssetDB with the given storage backend.

Source

pub fn add_listener(&self, listener: Arc<dyn DeltaListener>)

Register a delta listener. Returns index for removal.

Source

pub fn open(path: impl AsRef<Path>) -> Result<Arc<Self>>

Open a file-backed AssetDB at the given path (native only).

Source

pub fn in_memory() -> Result<Arc<Self>>

Create an in-memory AssetDB (wasm or testing).

Source

pub fn put(&self, id: &str, data: &[u8], metadata: Value) -> Result<()>

Put (upsert) an asset by ID. If the ID already exists, the data and metadata are replaced. The blob is content-addressed, so re-storing identical data is free.

Source

pub fn put_json( &self, id: &str, json_data: Value, metadata: Value, ) -> Result<()>

Put JSON inline (materials, skeletons, configs). Upsert by ID.

Source

pub fn tag(&self, id: &str, tags: &[&str]) -> Result<()>

Tag an entity. Additive — doesn’t remove existing tags.

Source

pub fn get(&self, id: &str) -> Result<Asset>

Get a single asset by exact ID. This is the primary access path.

let mesh = db.get("snake:mesh")?;
Source

pub fn has(&self, id: &str) -> bool

Check if an entity exists.

Source

pub fn get_entry(&self, id: &str) -> Result<AssetEntry>

Get just the metadata for an entity (no blob load).

Source

pub fn store( &self, asset_type: &str, name: &str, data: &[u8], metadata: Value, tags: &[&str], ) -> Result<AssetId>

Store with auto-generated ID. Returns the ID.

Source

pub fn store_json( &self, asset_type: &str, name: &str, json_data: Value, metadata: Value, tags: &[&str], ) -> Result<AssetId>

Store JSON with auto-generated ID. Returns the ID.

Source

pub fn load_by_name(&self, name: &str) -> Result<Asset>

Load by name (convenience — looks up “name:*” pattern).

Source

pub fn set_component( &self, entity: &str, component: &str, data: &[u8], metadata: Value, ) -> Result<()>

Set a component on an entity. Upserts “entity:component” in the DB.

Source

pub fn set_component_json( &self, entity: &str, component: &str, data: Value, metadata: Value, ) -> Result<()>

Set a JSON component on an entity.

Source

pub fn merge_component_json( &self, entity: &str, component: &str, patch: Value, metadata: Value, ) -> Result<()>

Merge fields into an existing JSON component. Creates if missing. Only the keys present in patch are overwritten; all other fields preserved.

Source

pub fn get_component(&self, entity: &str, component: &str) -> Result<Asset>

Get a component from an entity.

Source

pub fn has_component(&self, entity: &str, component: &str) -> bool

Check if an entity has a specific component.

Source

pub fn remove_component(&self, entity: &str, component: &str) -> Result<()>

Remove a component from an entity.

Source

pub fn components_of(&self, entity: &str) -> Result<Vec<String>>

List all component types attached to an entity.

db.components_of("player") → ["transform", "rigidbody", "collider", "mesh"]
Source

pub fn entities_with(&self, components: &[&str]) -> Result<Vec<String>>

Find all entity names that have ALL of the specified components.

db.entities_with(&["rigidbody", "transform"])
→ ["player", "enemy_1", "crate_3"]
Source

pub fn entities_with_any(&self, components: &[&str]) -> Result<Vec<String>>

Find all entity names that have ANY of the specified components.

Source

pub fn entity_snapshot(&self, entity: &str) -> Result<Value>

Get all components for an entity as a JSON object. Loads inline_data for JSON components, metadata for binary ones.

db.entity_snapshot("player")
→ { "transform": { "position": [0,1,0], ... },
     "rigidbody": { "mass": 1.0, ... } }
Source

pub fn spawn_from(&self, template_entity: &str, new_entity: &str) -> Result<()>

Spawn an entity from a template (prefab). Copies all components from source entity to a new entity name.

Source

pub fn destroy_entity(&self, entity: &str) -> Result<()>

Delete all components for an entity.

Source

pub fn query_dsl(&self, dsl: &Value) -> Result<Vec<AssetEntry>>

Query from JSON DSL — primary interface for DAG actors.

{ "type": "mesh", "tags": ["snake"], "$sort": "newest", "$limit": 5 }
Source

pub fn query(&self, q: &AssetQuery) -> Result<Vec<AssetEntry>>

Query metadata (no blob data).

Source

pub fn delete(&self, id: &str) -> Result<()>

Delete by ID.

Source

pub fn update_metadata( &self, id: &str, metadata: Option<Value>, tags: Option<Vec<String>>, ) -> Result<()>

Update metadata/tags.

Source

pub fn stats(&self) -> Result<Value>

Stats summary.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.