Skip to content

Commit

Permalink
remove register_format and register_format_type
Browse files Browse the repository at this point in the history
  • Loading branch information
ezpuzz committed Dec 26, 2020
1 parent a8a972d commit 9ad12da
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 413 deletions.
40 changes: 2 additions & 38 deletions amethyst_assets/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use amethyst_error::{Error, ResultExt};
#[cfg(feature = "profiler")]
use thread_profiler::profile_scope;

use crate::{processor::ProcessingState, FormatRegisteredData, Source};
use crate::{processor::ProcessingState, Source};

/// One of the three core traits of this crate.
///
Expand Down Expand Up @@ -63,19 +63,6 @@ pub trait Format<D: 'static>: objekt::Clone + Debug + Send + Sync + 'static {
fn import_simple(&self, _bytes: Vec<u8>) -> Result<D, Error> {
unimplemented!("You must implement either `import_simple` or `import`.")
}

/// Reads the given bytes and produces asset data.
///
/// You can implement `import_simple` instead of simpler formats.
///
fn import(&self, name: String, source: Arc<dyn Source>) -> Result<FormatValue<D>, Error> {
#[cfg(feature = "profiler")]
profile_scope!("import_asset");
let b = source
.load(&name)
.with_context(|_| crate::error::Error::Source)?;
Ok(FormatValue::data(self.import_simple(b)?))
}
}

objekt::clone_trait_object!(<D> Format<D>);
Expand All @@ -86,14 +73,10 @@ objekt::clone_trait_object!(<D> Format<D>);
/// **Note:** This trait should never be implemented manually.
/// Use the `register_format` macro to register it correctly.
/// See [FormatRegisteredData](trait.FormatRegisteredData.html) for the full example.
pub trait SerializableFormat<D: FormatRegisteredData + 'static>:
Format<D> + erased_serde::Serialize + 'static
{
pub trait SerializableFormat<D: 'static>: Format<D> + erased_serde::Serialize + 'static {
// Empty.
}

objekt::clone_trait_object!(<D> SerializableFormat<D>);

// Allow using dynamic types on sites that accept format as generic.
impl<D: 'static> Format<D> for Box<dyn Format<D>> {
fn name(&self) -> &'static str {
Expand All @@ -102,27 +85,8 @@ impl<D: 'static> Format<D> for Box<dyn Format<D>> {
fn import_simple(&self, bytes: Vec<u8>) -> Result<D, Error> {
self.deref().import_simple(bytes)
}

fn import(&self, name: String, source: Arc<dyn Source>) -> Result<FormatValue<D>, Error> {
self.deref().import(name, source)
}
}

impl<D: 'static> Format<D> for Box<dyn SerializableFormat<D>> {
fn name(&self) -> &'static str {
self.deref().name()
}
fn import_simple(&self, bytes: Vec<u8>) -> Result<D, Error> {
self.deref().import_simple(bytes)
}

fn import(&self, name: String, source: Arc<dyn Source>) -> Result<FormatValue<D>, Error> {
self.deref().import(name, source)
}
}

impl<D: FormatRegisteredData + 'static> SerializableFormat<D> for Box<dyn SerializableFormat<D>> {}

/// The `Ok` return value of `Format::import` for a given asset type `A`.
pub struct FormatValue<D> {
/// The format data.
Expand Down
324 changes: 0 additions & 324 deletions amethyst_assets/src/dyn_format.rs

This file was deleted.

Loading

0 comments on commit 9ad12da

Please sign in to comment.