mr_bundle/
manifest.rs

1use std::collections::HashMap;
2use std::fmt::Debug;
3
4/// The identifier for a resource in the manifest.
5pub type ResourceIdentifier = String;
6
7/// A Manifest describes the resources in a [`Bundle`](crate::Bundle).
8///
9/// A manifest implementation is expected to describe a set of resources that
10/// it intends to be bundled with. The resources are expected to be identifiable
11/// by a [`ResourceIdentifier`], which is a string.
12///
13/// The bundler uses [`generate_resource_ids`](Manifest::generate_resource_ids) to
14/// request that the manifest produce a set of resource ids. The manifest must
15/// replace its resource locators with the generated ids and return the pairs of
16/// ids and resource locations to the bundler.
17pub trait Manifest:
18    Clone + Sized + PartialEq + Eq + Debug + serde::Serialize + serde::de::DeserializeOwned
19{
20    /// Ask the manifest to produce resource ids and a locator for the resources.
21    ///
22    /// After the operations complete, the manifest must have replaced its resource
23    /// locators with the generated ids. The returned map must contain the pairs of
24    /// resource ids and their original locators.
25    ///
26    /// This operation is required to be idempotent if it is called multiple times. The first
27    /// call is expected to mutate the manifest so that its resources refer to ids instead of the
28    /// original resource locators. If called again, it can't return useful locators but the ids
29    /// must be the same as the first call.
30    fn generate_resource_ids(&mut self) -> HashMap<ResourceIdentifier, String>;
31
32    /// The list of resources referenced in the manifest data.
33    ///
34    /// This must return the same value before or after the call to [`generate_resource_ids`](Manifest::generate_resource_ids).
35    fn resource_ids(&self) -> Vec<ResourceIdentifier>;
36
37    /// The file name of the manifest file.
38    ///
39    /// This is recommended to contain a file extension, but it is not required.
40    #[cfg(feature = "fs")]
41    #[cfg_attr(docsrs, doc(cfg(feature = "fs")))]
42    fn file_name() -> &'static str;
43
44    /// The file extension to use when writing the bundle to the filesystem.
45    #[cfg(feature = "fs")]
46    #[cfg_attr(docsrs, doc(cfg(feature = "fs")))]
47    fn bundle_extension() -> &'static str;
48}