pub struct ResourceDesc {
pub dedicated: bool,
pub data: Or<Box<dyn Any>, NonNull<u8>>,
/* private fields */
}Expand description
A descriptor for registration of a resource.
Normally, resource is owned by an ECS instance, but type-erased raw pointer
can also be considered as a resource. In that case, clients must guarantee
safety about the pointer. ResourceDesc::with_owned and
ResourceDesc::with_ptr are methods about the ownership.
Fields§
§dedicated: bool§data: Or<Box<dyn Any>, NonNull<u8>>Implementations§
Source§impl ResourceDesc
impl ResourceDesc
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty ResourceDesc.
§Examples
use my_ecs::prelude::ResourceDesc;
let desc = ResourceDesc::new();Sourcepub fn with_dedicated(self, is_dedicated: bool) -> Self
pub fn with_dedicated(self, is_dedicated: bool) -> Self
Sets whether the resource is dedicated to the descriptor then returns the result.
Dedicated resource is only accessable from main worker for now.
§Examples
use my_ecs::prelude::ResourceDesc;
let desc = ResourceDesc::new().with_dedicated(true);Sourcepub fn with_owned<R: Resource>(self, data: R) -> Self
pub fn with_owned<R: Resource>(self, data: R) -> Self
Sets the given owned resource to the descriptor then returns the result.
§Examples
use my_ecs::prelude::*;
#[derive(Resource)] struct R(i32);
let desc = ResourceDesc::new().with_owned(R(0));Sourcepub unsafe fn with_ptr<R: Resource>(self, data: *mut R) -> Self
pub unsafe fn with_ptr<R: Resource>(self, data: *mut R) -> Self
Sets the given pointer as a resource to the descriptor then returns the result.
§Safety
After registration the descriptor to an ECS instance, owner of the data must not access the data while the ECS instance is running because the ECS instance may read or write something on the data.
§Examples
use my_ecs::prelude::*;
#[derive(Resource)] struct R(i32);
let mut r = R(0);
let desc = unsafe { ResourceDesc::new().with_ptr(&mut r as *mut R) };Trait Implementations§
Source§impl Debug for ResourceDesc
impl Debug for ResourceDesc
Source§impl Default for ResourceDesc
impl Default for ResourceDesc
Auto Trait Implementations§
impl Freeze for ResourceDesc
impl !RefUnwindSafe for ResourceDesc
impl !Send for ResourceDesc
impl !Sync for ResourceDesc
impl Unpin for ResourceDesc
impl !UnwindSafe for ResourceDesc
Blanket Implementations§
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
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>
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>
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 more