pub trait DynamicBundle: Sized {
type Effect;
// Required methods
unsafe fn get_components(
ptr: MovingPtr<'_, Self>,
func: &mut impl FnMut(StorageType, OwningPtr<'_>),
);
unsafe fn apply_effect(
ptr: MovingPtr<'_, MaybeUninit<Self>>,
entity: &mut EntityWorldMut<'_>,
);
}
Expand description
The parts from Bundle
that don’t require statically knowing the components of the bundle.
Required Associated Types§
Required Methods§
Sourceunsafe fn get_components(
ptr: MovingPtr<'_, Self>,
func: &mut impl FnMut(StorageType, OwningPtr<'_>),
)
unsafe fn get_components( ptr: MovingPtr<'_, Self>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), )
Moves the components out of the bundle.
§Safety
For callers:
- Must be called exactly once before
apply_effect
- The
StorageType
argument passed intofunc
must be correct for the component being fetched. apply_effect
must be called exactly once after this has been called ifEffect: !NoBundleEffect
For implementors:
- Implementors of this function must convert
ptr
into pointers to individual components stored withinSelf
and callfunc
on each of them in exactly the same order asBundle::get_component_ids
andBundleFromComponents::from_components
. - If any part of
ptr
is to be accessed inapply_effect
, it must not be dropped at any point in this function. Callingbevy_ptr::deconstruct_moving_ptr
in this function automatically ensures this.
Sourceunsafe fn apply_effect(
ptr: MovingPtr<'_, MaybeUninit<Self>>,
entity: &mut EntityWorldMut<'_>,
)
unsafe fn apply_effect( ptr: MovingPtr<'_, MaybeUninit<Self>>, entity: &mut EntityWorldMut<'_>, )
Applies the after-effects of spawning this bundle.
This is applied after all residual changes to the World
, including flushing the internal command
queue.
§Safety
For callers:
- Must be called exactly once after
get_components
has been called. ptr
must point to the instance ofSelf
thatget_components
was called on, all of fields that were moved out of inget_components
will not be valid anymore.
For implementors:
- If any part of
ptr
is to be accessed in this function, it must not be dropped at any point inget_components
. Callingbevy_ptr::deconstruct_moving_ptr
inget_components
automatically ensures this is the case.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.