Struct EcsCommandError
pub struct EcsCommandError {
pub kind: EcsCommandErrorKind,
/* private fields */
}Expand description
Owned failure. Use Self::into_bundle to recover a retained typed bundle.
A wrong requested type returns the entire error unchanged.
Fields§
§kind: EcsCommandErrorKindImplementations§
§impl EcsCommandError
impl EcsCommandError
pub fn into_bundle<B>(self) -> Result<B, EcsCommandError>where
B: Bundle + 'static,
pub fn into_bundle<B>(self) -> Result<B, EcsCommandError>where
B: Bundle + 'static,
Recovers a failed spawn/dependency bundle of its exact original tuple type.
Stale insert targets retain bundles. Errors returned by World::insert
itself (duplicate component types) have none: that API consumed the input.
use ferravex_engine::{ecs::World, ecs_commands::{EcsCommandBuffer, TokenError}};
use ferravex_engine::commands::CommandFailurePolicy;
let mut world = World::new(); // Not yet prepared for owned String bundles.
let mut commands = EcsCommandBuffer::new(2, 1);
let failed = commands.spawn(20, (String::from("actor"),)).unwrap();
let mut owned = None;
let report = commands.apply_report(&mut world, 1, CommandFailurePolicy::StopOnError,
|failure| owned = Some(failure.error.into_bundle::<(String,)>().unwrap())).unwrap();
assert_eq!(report.commands.failed, 1);
assert_eq!(commands.take_spawn(&failed), Err(TokenError::DependencyFailed));
commands.reset().unwrap(); // Cancels old tails and expires every old token.
world.prepare_entities(1).unwrap();
world.prepare_component::<String>(1).unwrap();
let fresh = commands.spawn(21, owned.unwrap()).unwrap();
let mut report = commands.apply_report(&mut world, 1, CommandFailurePolicy::Continue,
|_| unreachable!()).unwrap();
let entity = report.take_spawn(&fresh).unwrap();
assert_eq!(report.take_spawn(&fresh), Err(TokenError::AlreadyTaken));
assert_eq!(&**world.get::<&String>(entity).unwrap(), "actor");
assert_eq!(commands.take_spawn(&failed), Err(TokenError::StaleEpoch));
commands.remove::<String>(22, &fresh).unwrap(); // Claiming kept target resolution.
commands.apply_report(&mut world, 1, CommandFailurePolicy::Continue,
|_| unreachable!()).unwrap();
assert!(!world.has::<String>(entity));Trait Implementations§
Auto Trait Implementations§
impl Freeze for EcsCommandError
impl !RefUnwindSafe for EcsCommandError
impl !Send for EcsCommandError
impl !Sync for EcsCommandError
impl Unpin for EcsCommandError
impl !UnwindSafe for EcsCommandError
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
Mutably borrows from an owned value. Read more