Skip to main content

Format

Trait Format 

Source
pub trait Format:
    Send
    + Sync
    + 'static {
    type Asset: AssetKind;

    // Required methods
    fn id(&self) -> &'static str;
    fn extensions(&self) -> &'static [&'static str];
    fn decode(
        &self,
        file: &AssetPath,
        bytes: &[u8],
        cx: &DecodeCx<'_>,
    ) -> Result<Self::Asset, Vec<ContentError>>;

    // Provided methods
    fn sniff(&self, bytes: &[u8]) -> bool { ... }
    fn max_bytes(&self) -> usize { ... }
}
Expand description

A file format: reads one AssetKind from a file’s bytes.

Required Associated Types§

Source

type Asset: AssetKind

The kind it reads.

Required Methods§

Source

fn id(&self) -> &'static str

Stable id, e.g. "png", "tiled-tmx", "yarn": one per format of a kind.

Source

fn extensions(&self) -> &'static [&'static str]

File extensions this format claims, lowercase, without the dot. A format that only stands in another’s place (a one-bit picture at a PNG’s path) claims none and is found by sniff.

Source

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

Every problem found, each with file and place; never a panic.

Provided Methods§

Source

fn sniff(&self, bytes: &[u8]) -> bool

True if these bytes look like this format (magic bytes); false when the format has none.

Source

fn max_bytes(&self) -> usize

The most bytes it reads: a bigger file is refused before decode sees it. DEFAULT_MAX_BYTES unless the format says.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Format for AudioManifestRon

Source§

impl Format for CreditsRon

Source§

impl Format for Dithered

Available on crate feature png only.
Source§

impl Format for FontAtlasRon

Source§

impl Format for LangPackRon

Source§

impl Format for LightingRon

Source§

impl Format for NamesRon

Source§

impl Format for OggVorbis

Source§

impl Format for OggVorbisTrack

Source§

impl Format for OneBitFile

Source§

impl Format for OneBitInfo

Source§

impl Format for PaletteRon

Source§

impl Format for PatternMapRon

Source§

impl Format for Png

Available on crate feature png only.
Source§

impl Format for PngInfo

Source§

impl Format for TargetRon

Source§

impl Format for Wav

Source§

impl<A: ActionSet> Format for KeymapRon<A>

Source§

impl<D: Directive + 'static> Format for Dlg<D>

Source§

impl<K: AssetKind + DeserializeOwned> Format for Packed<K>

Source§

type Asset = K

Source§

impl<S: DeserializeOwned + 'static, P: DeserializeOwned + 'static> Format for CinematicRon<S, P>

Source§

impl<T: AssetKind + DeserializeOwned> Format for Ron<T>

Source§

type Asset = T

Source§

impl<T: Copy + Default + 'static, F: MapFeature + 'static> Format for MapText<T, F>

Source§

type Asset = GridMap<T, F>