pub struct BuiltInResource<T>where
T: TypedResourceData,{
pub id: PathBuf,
pub data_source: Option<DataSource>,
pub resource: Resource<T>,
}Expand description
Built-in resource is a resource embedded in the application executable file. It is a very useful mechanism when you need to bundle all game resources and put them in the executable file.
§Registration
Every built-in resource must be registered in a resource manager to be accessible via standard
crate::manager::ResourceManager::request method. It could be done pretty easily:
use fyrox_resource::{
builtin::BuiltInResource,
core::{reflect::prelude::*, type_traits::prelude::*, visitor::prelude::*, Uuid},
manager::ResourceManager,
Resource, ResourceData,
};
use std::{error::Error, path::Path};
#[derive(TypeUuidProvider, Default, Debug, Clone, Visit, Reflect)]
#[type_uuid(id = "00d036bb-fbed-47f7-94e3-b3fce93dee17")]
struct MyResource {
some_data: String,
}
impl ResourceData for MyResource {
fn type_uuid(&self) -> Uuid {
<Self as TypeUuidProvider>::type_uuid()
}
fn save(&mut self, _path: &Path) -> Result<(), Box<dyn Error>> {
Ok(())
}
fn can_be_saved(&self) -> bool {
false
}
fn try_clone_box(&self) -> Option<Box<dyn ResourceData>> {
Some(Box::new(self.clone()))
}
}
fn register_built_in_resource(resource_manager: &ResourceManager) {
let id = "MyResourceId";
let some_data = "This string is a built-in resource with MyResourceId id.";
let resource = Resource::new_embedded(MyResource {
some_data: some_data.into(),
});
resource_manager.register_built_in_resource(BuiltInResource::new_no_source(id, resource));
assert_eq!(
resource_manager
.request::<MyResource>(id)
.data_ref()
.some_data,
some_data,
)
}Fields§
§id: PathBufId of the built-in resource.
data_source: Option<DataSource>Initial data, from which the resource is created from.
resource: Resource<T>Ready-to-use (“loaded”) resource.
Implementations§
Source§impl<T> BuiltInResource<T>where
T: TypedResourceData,
impl<T> BuiltInResource<T>where
T: TypedResourceData,
Sourcepub fn new<F>(
id: impl AsRef<Path>,
data_source: DataSource,
make: F,
) -> BuiltInResource<T>
pub fn new<F>( id: impl AsRef<Path>, data_source: DataSource, make: F, ) -> BuiltInResource<T>
Creates a new built-in resource with an id, a data source and function that creates the resource from the given data source.
Sourcepub fn new_no_source(
id: impl AsRef<Path>,
resource: Resource<T>,
) -> BuiltInResource<T>
pub fn new_no_source( id: impl AsRef<Path>, resource: Resource<T>, ) -> BuiltInResource<T>
Creates a new built-in resource from an id and arbitrary resource.
Trait Implementations§
Source§impl<T> Clone for BuiltInResource<T>where
T: TypedResourceData,
impl<T> Clone for BuiltInResource<T>where
T: TypedResourceData,
Source§fn clone(&self) -> BuiltInResource<T>
fn clone(&self) -> BuiltInResource<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T> From<BuiltInResource<T>> for UntypedBuiltInResourcewhere
T: TypedResourceData,
impl<T> From<BuiltInResource<T>> for UntypedBuiltInResourcewhere
T: TypedResourceData,
Source§fn from(value: BuiltInResource<T>) -> UntypedBuiltInResource
fn from(value: BuiltInResource<T>) -> UntypedBuiltInResource
Converts to this type from the input type.
Auto Trait Implementations§
impl<T> Freeze for BuiltInResource<T>
impl<T> !RefUnwindSafe for BuiltInResource<T>
impl<T> Send for BuiltInResource<T>
impl<T> Sync for BuiltInResource<T>where
T: Sync,
impl<T> Unpin for BuiltInResource<T>where
T: Unpin,
impl<T> !UnwindSafe for BuiltInResource<T>
Blanket Implementations§
Source§impl<T> AsyncTaskResult for T
impl<T> AsyncTaskResult for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T, U> ObjectOrVariant<T> for Uwhere
PhantomData<U>: ObjectOrVariantHelper<T, U>,
impl<T, U> ObjectOrVariant<T> for Uwhere
PhantomData<U>: ObjectOrVariantHelper<T, U>,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.