pub struct Layer {
pub name: &'static str,
pub files: Files,
pub private: bool,
pub test: bool,
pub left_out: &'static [&'static str],
pub stands_for: Option<ContentHash>,
}Expand description
One layer of the bundle.
Fields§
§name: &'static strThe prefix its files are shown with (base shows data/x.ron as
base/data/x.ron).
files: FilesIts files.
private: boolWhether its files may not be handed out (bought art).
test: boolWhether it holds test files, which a build that ships leaves out.
left_out: &'static [&'static str]The paths (sorted) of the files this layer leaves out on purpose.
stands_for: Option<ContentHash>The fingerprint of the content this layer stands for, if it holds
every file of a bundle (a pack’s layer, Layer::standing_for):
Bundle::fingerprint then takes that, and not its files.
Implementations§
Source§impl Layer
impl Layer
Sourcepub const fn dir(name: &'static str, dir: &'static Dir<'static>) -> Self
pub const fn dir(name: &'static str, dir: &'static Dir<'static>) -> Self
A layer of the directory dir, shown as name.
Sourcepub const fn table(
name: &'static str,
files: &'static [(&'static str, &'static [u8])],
) -> Self
pub const fn table( name: &'static str, files: &'static [(&'static str, &'static [u8])], ) -> Self
A layer of the table files (sorted by path), shown as name.
Sourcepub fn owned(
name: String,
files: BTreeMap<String, Vec<u8>>,
) -> Result<Self, LayerError>
pub fn owned( name: String, files: BTreeMap<String, Vec<u8>>, ) -> Result<Self, LayerError>
A layer of files handed in at run time (a mod, a folder read from
disk), each at its path (relative to the layer’s root,
/-separated), shown as name. The name, paths and bytes are kept
for the life of the program (leaked once), so reads of them are
&'static like the embedded layers’. Make each layer once.
use std::collections::BTreeMap;
use shuyi_assets::bundle::{Bundle, Layer};
static BASE: &[(&str, &[u8])] = &[("data/a.ron", b"base a")];
let files = BTreeMap::from([("data/a.ron".to_owned(), b"mod a".to_vec())]);
let layer = Layer::owned("mods/more".to_owned(), files).unwrap();
let bundle = Bundle::new(vec![layer, Layer::table("base", BASE)]);
assert_eq!(bundle.file("data/a.ron"), Some("mod a"));
assert_eq!(bundle.display_path("data/a.ron"), "mods/more/data/a.ron");§Errors
A path that is empty, absolute, has a backslash, goes up a folder
(..) or has an empty or . part, naming the layer and the path.
Nothing is kept then.
Sourcepub fn replace(&self, path: &str, bytes: Vec<u8>) -> bool
pub fn replace(&self, path: &str, bytes: Vec<u8>) -> bool
Puts bytes at path in this layer (a file changed on disk), for
every bundle that has the layer, and says whether it did: only a
layer handed in at run time (Layer::owned) changes, and only at a
path it could have been made with.
A hot reload’s way in, in debug builds: the old bytes are leaked, as
the layer’s files are, so every &'static read of them stays valid.
Sourcepub const fn leaving_out(self, paths: &'static [&'static str]) -> Self
pub const fn leaving_out(self, paths: &'static [&'static str]) -> Self
This layer, leaving out the files at paths (sorted, relative to
its root) on purpose: they are the game’s, but this build does
without them.
Sourcepub const fn standing_for(self, content: ContentHash) -> Self
pub const fn standing_for(self, content: ContentHash) -> Self
This layer, standing for the bundle whose fingerprint is content
(Bundle::fingerprint): it holds every file of that bundle, as a
pack does of the bundle it was baked from, so a bundle with it has
that bundle’s fingerprint.
Sourcepub fn target(&self) -> Option<&'static str>
pub fn target(&self) -> Option<&'static str>
The target this layer is for, as its name says after the last
TARGET_MARK: playdate for assets@playdate. None for a
layer for every target (assets).