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 materials;
32mod metadata;
33mod uuid;
34
35pub use handle::*;
36pub use materials::*;
37pub use metadata::*;
38pub use uuid::*;
39
40/// A marker trait for types that can be managed by the asset system.
41///
42/// This trait's primary purpose is to categorize a type, making it eligible for
43/// use within the engine's asset infrastructure (e.g., in a `Handle<T>`).
44///
45/// The supertraits enforce critical safety guarantees:
46/// - `Send` + `Sync`: The asset type can be safely shared and sent between threads.
47///   This is essential for background loading.
48/// - `'static`: The asset type does not contain any non-static references, ensuring
49///   it can be stored for the lifetime of the application.
50///
51/// # Examples
52///
53/// ```
54/// use khora_core::asset::Asset;
55///
56/// // A simple struct representing a texture.
57/// struct Texture {
58///     // ... fields
59/// }
60///
61/// // By implementing Asset, `Texture` can now be used by the asset system.
62/// impl Asset for Texture {}
63/// ```
64pub trait Asset: Send + Sync + 'static {}