Skip to main content

Layer

Struct Layer 

Source
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 str

The prefix its files are shown with (base shows data/x.ron as base/data/x.ron).

§files: Files

Its files.

§private: bool

Whether its files may not be handed out (bought art).

§test: bool

Whether 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

Source

pub const fn dir(name: &'static str, dir: &'static Dir<'static>) -> Layer

A layer of the directory dir, shown as name.

Source

pub const fn table( name: &'static str, files: &'static [(&'static str, &'static [u8])], ) -> Layer

A layer of the table files (sorted by path), shown as name.

Source

pub fn owned( name: String, files: BTreeMap<String, Vec<u8>>, ) -> Result<Layer, 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.

Source

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.

Source

pub const fn private(self) -> Layer

This layer, marked private.

Source

pub const fn test(self) -> Layer

This layer, marked as test files.

Source

pub const fn leaving_out(self, paths: &'static [&'static str]) -> Layer

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.

Source

pub const fn standing_for(self, content: ContentHash) -> Layer

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.

Source

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).

Trait Implementations§

Source§

impl Clone for Layer

Source§

fn clone(&self) -> Layer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Layer

Source§

impl Debug for Layer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Layer

§

impl RefUnwindSafe for Layer

§

impl Send for Layer

§

impl Sync for Layer

§

impl Unpin for Layer

§

impl UnsafeUnpin for Layer

§

impl UnwindSafe for Layer

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.