Repository: bevyengine/bevy
File: crates/bevy_ecs/src/system/system_param.rs (Rust)

Code before:
    fn init_state(_world: &mut World) -> Self::State {}

    fn init_access(
        _state: &Self::State,
        system_meta: &mut SystemMeta,
        component_access_set: &mut FilteredAccessSet,
        _world: &mut World,
    ) {
        assert!(
            !component_access_set.combined_access().has_any_read(),
            "DeferredWorld in system {} conflicts with a previous access.",
            system_meta.name,
        );
        component_access_set.write_all();
    }

    unsafe fn get_param<'world, 'state>(
        _state: &'state mut Self::State,
        _system_meta: &SystemMeta,
        world: UnsafeWorldCell<'world>,
        _change_tick: Tick,
    ) -> Self::Item<'world, 'state> {
        world.into_deferred()
    }
}

/// A [`SystemParam`] that provides a system-private value of `T` that persists across system calls.
///
/// The initial value is created by calling `T`'s [`FromWorld::from_world`] (or [`Default::default`] if `T: Default`).
///
/// A local may only be accessed by the system itself and is therefore not visible to other systems.
/// If two or more systems specify the same local type each will have their own unique local.
/// If multiple [`SystemParam`]s within the same system each specify the same local type
/// each will get their own distinct data storage.
///
/// The supplied lifetime parameter is the [`SystemParam`]s `'s` lifetime.
///
/// # Examples
///
/// ```
/// # use bevy_ecs::prelude::*;
/// # let world = &mut World::default();
/// fn counter(mut count: Local<u32>) -> u32 {
///     *count += 1;
///     *count
/// }
/// let mut counter_system = IntoSystem::into_system(counter);
/// counter_system.initialize(world);
///
/// // Counter is initialized to u32's default value of 0, and increases to 1 on first run.
/// assert_eq!(counter_system.run((), world).unwrap(), 1);

Review comment (suggestion):
I think this one, in `DeferredWorld::get_param`, is also relying on `init_access` having registered the access correctly.  I might either reword this to mention that, similar to `<&World>::get_param`, or punt it to a future PR in this series.  

Well, I guess that's also true for the other `get_param` changes here, but those are all delegating both `init_access` and `get_param` so they feel a lot more like a pass-through.

Code after:
    type State = ();
    type Item<'world, 'state> = DeferredWorld<'world>;

    fn init_state(_world: &mut World) -> Self::State {}

    fn init_access(
        _state: &Self::State,
        system_meta: &mut SystemMeta,
        component_access_set: &mut FilteredAccessSet,
        _world: &mut World,
    ) {
        assert!(
            !component_access_set.combined_access().has_any_read(),
            "DeferredWorld in system {} conflicts with a previous access.",
            system_meta.name,
        );
        component_access_set.write_all();
    }

    unsafe fn get_param<'world, 'state>(
        _state: &'state mut Self::State,
        _system_meta: &SystemMeta,
        world: UnsafeWorldCell<'world>,
        _change_tick: Tick,
    ) -> Self::Item<'world, 'state> {
        // SAFETY: Upheld by caller
        unsafe { world.into_deferred() }
    }
}

/// A [`SystemParam`] that provides a system-private value of `T` that persists across system calls.
///
/// The initial value is created by calling `T`'s [`FromWorld::from_world`] (or [`Default::default`] if `T: Default`).
///
/// A local may only be accessed by the system itself and is therefore not visible to other systems.
/// If two or more systems specify the same local type each will have their own unique local.
/// If multiple [`SystemParam`]s within the same system each specify the same local type
/// each will get their own distinct data storage.
///
/// The supplied lifetime parameter is the [`SystemParam`]s `'s` lifetime.
///
/// # Examples
///
/// ```
/// # use bevy_ecs::prelude::*;
/// # let world = &mut World::default();
/// fn counter(mut count: Local<u32>) -> u32 {
///     *count += 1;
///     *count
/// }
/// let mut counter_system = IntoSystem::into_system(counter);