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: EcsCommandErrorKind

Implementations§

§

impl EcsCommandError

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§

§

impl Debug for EcsCommandError

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.