Skip to main content

Formats

Struct Formats 

Source
pub struct Formats {
    pub limits: Limits,
    /* private fields */
}
Expand description

The formats of every kind (module docs).

Fields§

§limits: Limits

The limits Formats::load and Formats::load_under decode with.

Implementations§

Source§

impl Formats

Source

pub fn new() -> Self

A registry with no format at all.

Source

pub fn standard() -> Self

A registry with the engine’s standard formats, those that need nothing of the game (Formats::register_standard).

Source

pub fn register_standard(&mut self) -> Result<(), RegisterError>

Registers the engine’s standard formats after those already here: every format of the engine that needs nothing of the game. The formats that read a game’s own types (its map features, dialogue directives, actions, shots) or follow its rules (the glyphs it needs, its language rules) are the game’s to register, with them.

Source

pub fn register<F: Format>(&mut self, format: F) -> Result<(), RegisterError>

Adds format after the formats of its kind, unless one of them has its id or claims one of its extensions.

Source

pub fn replace<F: Format>( &mut self, format: F, ) -> Result<Vec<&'static str>, RegisterError>

Adds format in place of the formats of its kind that have its id or claim one of its extensions (after them all if none does), and returns their ids.

Source

pub fn register_import_settings<S: ImportSettings>( &mut self, ) -> Result<(), RegisterError>

Registers the section of import settings S (ADR-0057), so check_import_settings knows it. Refuses, in this order, a second section of its name, a type that can’t read () (a field with no default) and one that reads (shuyi_probe: ()) (it doesn’t deny unknown fields).

Source

pub fn import_settings_sections(&self) -> Vec<&'static str>

The names of the sections of import settings registered, in order.

Source

pub fn check_import_settings(&self, bundle: &Bundle) -> Vec<ContentError>

Every problem of every settings file of bundle (ADR-0057): a file that doesn’t read, a section no one registered or that doesn’t read as its type, and a <name>.meta whose file the bundle lacks (and doesn’t leave out on purpose) or is itself a settings file.

Source

pub fn ids<K: AssetKind>(&self) -> Vec<&'static str>

The ids of kind K’s formats, in the order they are tried.

Source

pub fn extensions<K: AssetKind>(&self) -> Vec<&'static str>

The extensions kind K’s formats claim, in their order.

Source

pub fn claims<K: AssetKind>(&self, path: &str) -> bool

Whether a format of kind K claims the extension of the file at path.

Source

pub fn decode<K: AssetKind>( &self, file: &AssetPath, bytes: &[u8], cx: &DecodeCx<'_>, ) -> Result<K, Vec<ContentError>>

The asset of kind K in bytes, the contents of file, by the lookup rule: the formats that sniff bytes in order, then the one that claims file’s extension. The first that decodes it gives the asset; when none does, the errors are the first one’s. A watch_decodes watch is told before and after.

Source

pub fn find<K: AssetKind>( &self, bundle: &Bundle, id: &str, ) -> Result<String, ContentError>

The path of the asset of kind K with id id: the file at id itself if bundle has one, else the one file at id and an extension kind K’s formats claim (images/card is images/card.png, or images/card.txtimg once a format claims that).

Source

pub fn load<K: AssetKind>( &self, bundle: &Bundle, id: &str, ) -> Result<K, Vec<ContentError>>

The asset of kind K with id id in bundle (Formats::find), decoded with the registry’s limits.

Source

pub fn load_under<K: AssetKind>( &self, bundle: &Bundle, dir: &str, ) -> Result<BTreeMap<&'static str, K>, Vec<ContentError>>

Every asset of kind K in bundle under directory dir ("" for the whole bundle): each file there whose extension a format of the kind claims, by path. Reports every problem of every file.

All or nothing over a tree: the assets come only when every file reads, and folders below dir are read too. A loader that checks each file after reading wants Formats::load_each instead.

Source

pub fn load_each<K: AssetKind>( &self, bundle: &Bundle, dir: &str, ) -> BTreeMap<&'static str, Result<K, Vec<ContentError>>>

Each asset of kind K directly inside directory dir of bundle ("" for the root), by path: each file there whose extension a format of the kind claims, with its asset or its errors.

File by file in one folder: a broken file leaves the others read, so checks that run after still see every good file, and folders below dir (which may hold another kind with the same extension) are not read. A missing folder gives an empty map.

Trait Implementations§

Source§

impl Debug for Formats

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Formats

Source§

fn default() -> Formats

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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