khora_lanes/asset_lane/loading/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//! Asset loading utilities.
16
17mod audio_loader_lane;
18mod mesh_loader_lane;
19mod texture_loader_lane;
20
21pub use audio_loader_lane::*;
22pub use mesh_loader_lane::*;
23pub use texture_loader_lane::*;
24
25use khora_core::asset::Asset;
26use std::error::Error;
27
28/// A trait for types that can load a specific kind of asset from a byte slice.
29///
30/// This represents the "Data Plane" part of asset loading. Implementors of this
31/// trait are responsible for the potentially CPU-intensive work of parsing and
32/// decoding raw file data into a usable, engine-ready asset type.
33///
34/// Each `AssetLoaderLane` is specialized for a single asset type `A`.
35pub trait AssetLoaderLane<A: Asset> {
36 /// Parses a byte slice and converts it into an instance of the asset `A`.
37 ///
38 /// # Parameters
39 /// - `bytes`: The raw byte data read from an asset file.
40 ///
41 /// # Returns
42 /// A `Result` containing the loaded asset on success, or a boxed dynamic
43 /// error on failure. The error must be thread-safe.
44 fn load(&self, bytes: &[u8]) -> Result<A, Box<dyn Error + Send + Sync>>;
45}