pub struct Opaque;Expand description
Marker occupying the Params position in step and handler traits to
indicate that a closure manages its own resource access via
world.resource::<T>() rather than through Param resolution.
Opaque is not a Param. It exists solely so the compiler can
distinguish three disjoint impl tiers without coherence conflicts:
Params type | Function shape | Resolution |
|---|---|---|
() | FnMut(E) | No resources needed |
(P0,) … (P0..P7,) | fn(Res<A>, ResMut<B>, E) | Build-time Param::init, dispatch-time Param::fetch |
Opaque | FnMut(&mut World, E) | None — caller owns all access |
Because &mut World does not implement Param, the Opaque impls
are always disjoint from the arity-based impls — the compiler infers
Params unambiguously from the closure/function signature.
§When to use
Prefer named functions with Param parameters — they resolve to a
direct pointer dereference per resource (single deref, no HashMap
lookup). Use Opaque closures as an escape hatch when:
- You need conditional resource access (different resources depending on runtime state).
- You need access to a resource whose type isn’t known at build time.
- You’re prototyping and want to defer the named-function refactor.
§Example
ⓘ
// Named function — preferred, hot path:
pipeline.guard(check_risk, ®) // fn(Res<Config>, &Order) -> bool
// Arity-0 closure — no World access:
pipeline.guard(|o: &Order| o.price > 100.0, ®)
// Opaque closure — escape hatch, HashMap lookups:
pipeline.guard(|w: &mut World, o: &Order| {
let cfg = w.resource::<Config>();
o.price > cfg.threshold
}, ®)Trait Implementations§
Source§impl<C, Out, F: FnMut(&mut C, &mut World) -> Out + 'static> IntoCtxProducer<C, Out, Opaque> for F
impl<C, Out, F: FnMut(&mut C, &mut World) -> Out + 'static> IntoCtxProducer<C, Out, Opaque> for F
Source§impl<C, In, Out, F: FnMut(&mut C, &mut World, &In) -> Out + 'static> IntoCtxRefStep<C, In, Out, Opaque> for F
impl<C, In, Out, F: FnMut(&mut C, &mut World, &In) -> Out + 'static> IntoCtxRefStep<C, In, Out, Opaque> for F
Source§impl<C, In, Out, F: FnMut(&mut C, &mut World, In) -> Out + 'static> IntoCtxStep<C, In, Out, Opaque> for F
impl<C, In, Out, F: FnMut(&mut C, &mut World, In) -> Out + 'static> IntoCtxStep<C, In, Out, Opaque> for F
Source§impl<E, F: FnMut(&mut World, E) + Send + 'static> IntoHandler<E, Opaque> for F
impl<E, F: FnMut(&mut World, E) + Send + 'static> IntoHandler<E, Opaque> for F
Source§type Handler = OpaqueHandler<F>
type Handler = OpaqueHandler<F>
The concrete handler type produced.
Source§fn into_handler(self, _registry: &Registry) -> Self::Handler
fn into_handler(self, _registry: &Registry) -> Self::Handler
Convert this function into a handler, resolving parameters from the registry.
Source§impl<Acc, In, Out, F: FnMut(&mut World, &mut Acc, &In) -> Out + 'static> IntoRefScanStep<Acc, In, Out, Opaque> for F
impl<Acc, In, Out, F: FnMut(&mut World, &mut Acc, &In) -> Out + 'static> IntoRefScanStep<Acc, In, Out, Opaque> for F
Auto Trait Implementations§
impl Freeze for Opaque
impl RefUnwindSafe for Opaque
impl Send for Opaque
impl Sync for Opaque
impl Unpin for Opaque
impl UnsafeUnpin for Opaque
impl UnwindSafe for Opaque
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