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