khora_core/asset/mod.rs
1// Copyright 2025 eraflo
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Provides the foundational traits and primitive types for Khora's asset system.
16//!
17//! This module defines the "common language" for all asset-related operations in the
18//! engine. It contains the core contracts that other crates will implement or use,
19//! but it has no knowledge of how assets are loaded or stored.
20//!
21//! The key components are:
22//! - The [`Asset`] trait: A marker for all types that can be treated as assets.
23//! - Stable, unique identifiers used to reference assets throughout the engine.
24//! - Abstract interfaces for loading and managing assets.
25//!
26//! These low-level primitives are the foundation upon which higher-level systems,
27//! such as an asset database or a virtual file system (VFS), are built in other
28//! crates.
29
30mod handle;
31mod metadata;
32mod uuid;
33
34pub use handle::*;
35pub use metadata::*;
36pub use uuid::*;
37
38/// A marker trait for types that can be managed by the asset system.
39///
40/// This trait's primary purpose is to categorize a type, making it eligible for
41/// use within the engine's asset infrastructure (e.g., in a `Handle<T>`).
42///
43/// The supertraits enforce critical safety guarantees:
44/// - `Send` + `Sync`: The asset type can be safely shared and sent between threads.
45/// This is essential for background loading.
46/// - `'static`: The asset type does not contain any non-static references, ensuring
47/// it can be stored for the lifetime of the application.
48///
49/// # Examples
50///
51/// ```
52/// use khora_core::asset::Asset;
53///
54/// // A simple struct representing a texture.
55/// struct Texture {
56/// // ... fields
57/// }
58///
59/// // By implementing Asset, `Texture` can now be used by the asset system.
60/// impl Asset for Texture {}
61/// ```
62pub trait Asset: Send + Sync + 'static {}