pub trait OnceExt<Marker> {
type System: System;
// Required method
fn once(self) -> Self::System;
}Expand description
Adds .once() to a function/closure whose parameters
are valid SystemParams and whose return type is Option<()>,
registering it as a system that runs on every tick of whichever stage
it’s added to until it returns Some(()), then never runs again.
This replaces manually tracking a “have I already done this” flag with
a Local<bool>: return None from the function to mean “not ready,
try again next tick” and Some(()) to mean “done, retire me”.
ⓘ
fn setup(mut commands: Commands, pbr: Option<Res<PBR>>) -> Option<()> {
let pbr = pbr?;
if pbr.cubemap_material_inst == RawAssetHandle::default() {
return None; // not ready yet — try again next tick
}
commands.spawn(/* ... */);
Some(()) // done — never runs again
}
app.add_system(SystemStage::PreUpdate, setup.once());Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".