Attribute Macro bevy_defer::async_access

source ·
#[async_access]
Expand description

Mirror an impl block to an async access component.

§Requirements

  • For type MyResource, there must be a type AsyncMyResource with an accessible field 0 being AsyncResource<MyResource>. This is the semantics of the derive macros.

  • All functions must have &self or &mut self receivers.

  • Outputs must be 'static.

  • Does not support async functions, since it’s currently difficult to get a static future with a self receiver. Return impl Future + 'static instead.

use module::{Character, AsyncCharacter};
#[async_access]
impl Character {
    fn get_name(&self) -> String {
        ..
    }
    fn shoot(&mut self, angle: f32) {
        ..
    }
}

§Arguments

  • #[async_access(must_exist)]

    This will unwrap the results instead of returning AccessResult. Useful on resources that should always be available.