mr_bundle/
manifest.rs

1use std::path::PathBuf;
2
3use crate::location::Location;
4
5/// A Manifest describes the resources in a [`Bundle`](crate::Bundle) and how
6/// to pack and unpack them.
7///
8/// Regardless of the format of your Manifest, it must contain a set of Locations
9/// describing where to find resources, and this trait must implement `locations`
10/// properly to match the data contained in the manifest.
11///
12/// You must also specify a relative path for the Manifest, and the extension
13/// for the bundle file, if you are using the "packing" feature.
14pub trait Manifest:
15    Clone + Sized + PartialEq + Eq + serde::Serialize + serde::de::DeserializeOwned
16{
17    /// The list of Locations referenced in the manifest data. This must be
18    /// correctly implemented to enable resource resolution.
19    fn locations(&self) -> Vec<Location>;
20
21    /// When unpacking the bundle into a directory structure, this becomes
22    /// the relative path of the manifest file.
23    #[cfg(feature = "packing")]
24    fn path() -> PathBuf;
25
26    /// When packing a bundle from a directory structure, the bundle file gets
27    /// this extension.
28    #[cfg(feature = "packing")]
29    fn bundle_extension() -> &'static str;
30
31    /// Get only the Bundled locations
32    fn bundled_paths(&self) -> Vec<PathBuf> {
33        self.locations()
34            .into_iter()
35            .filter_map(|loc| {
36                if let Location::Bundled(path) = loc {
37                    Some(path)
38                } else {
39                    None
40                }
41            })
42            .collect()
43    }
44}