1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use {std::path::Path, uuid::Uuid};

pub use eyre;

/// Object to register sub-assets when importing super-asset.
pub trait Registry {
    /// Register asset at source path, assigning specified importer.
    /// Source path must be absolute.
    fn store(
        &mut self,
        source: &Path,
        source_format: &str,
        native_format: &str,
        tags: &[&str],
    ) -> eyre::Result<Uuid>;

    /// Returns native path to asset with specified uuid.
    fn fetch(&mut self, asset: &Uuid) -> eyre::Result<Box<Path>>;
}

pub trait Importer: Send + Sync {
    /// Returns name of the importer
    fn name(&self) -> &str;

    /// Returns name of the source format
    fn source(&self) -> &str;

    /// Returns name of the native format
    fn native(&self) -> &str;

    /// Imports asset from source file, saving result to native file.
    /// Register sub-assets if necessary.
    fn import(
        &self,
        source_path: &Path,
        native_path: &Path,
        registry: &mut dyn Registry,
    ) -> eyre::Result<()>;
}