Skip to main content

Opaque

Struct Opaque 

Source
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 typeFunction shapeResolution
()FnMut(E)No resources needed
(P0,)(P0..P7,)fn(Res<A>, ResMut<B>, E)Build-time Param::init, dispatch-time Param::fetch
OpaqueFnMut(&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, &reg)    // fn(Res<Config>, &Order) -> bool

// Arity-0 closure — no World access:
pipeline.guard(|o: &Order| o.price > 100.0, &reg)

// Opaque closure — escape hatch, HashMap lookups:
pipeline.guard(|w: &mut World, o: &Order| {
    let cfg = w.resource::<Config>();
    o.price > cfg.threshold
}, &reg)

Trait Implementations§

Source§

impl<C, Out, F: FnMut(&mut C, &mut World) -> Out + 'static> IntoCtxProducer<C, Out, Opaque> for F

Source§

type Step = CtxOpaqueProducer<F>

The concrete resolved producer type.
Source§

fn into_ctx_producer(self, _registry: &Registry) -> Self::Step

Resolve Param state from the registry and produce a step.
Source§

impl<C, In, Out, F: FnMut(&mut C, &mut World, &In) -> Out + 'static> IntoCtxRefStep<C, In, Out, Opaque> for F

Source§

type Step = CtxOpaqueRefStep<F>

The concrete resolved step type.
Source§

fn into_ctx_ref_step(self, _registry: &Registry) -> Self::Step

Resolve Param state from the registry and produce a step.
Source§

impl<C, In, Out, F: FnMut(&mut C, &mut World, In) -> Out + 'static> IntoCtxStep<C, In, Out, Opaque> for F

Source§

type Step = CtxOpaqueStep<F>

The concrete resolved step type.
Source§

fn into_ctx_step(self, _registry: &Registry) -> Self::Step

Resolve Param state from the registry and produce a step.
Source§

impl<E, F: FnMut(&mut World, E) + Send + 'static> IntoHandler<E, Opaque> for F

Source§

type Handler = OpaqueHandler<F>

The concrete handler type produced.
Source§

fn into_handler(self, _registry: &Registry) -> Self::Handler

Convert this function into a handler, resolving parameters from the registry.
Source§

impl<Out, F: FnMut(&mut World) -> Out + 'static> IntoProducer<Out, Opaque> for F

Source§

type Step = OpaqueProducer<F>

The concrete resolved producer type.
Source§

fn into_producer(self, _registry: &Registry) -> Self::Step

Resolve Param state from the registry and produce a step.
Source§

impl<Acc, In, Out, F: FnMut(&mut World, &mut Acc, &In) -> Out + 'static> IntoRefScanStep<Acc, In, Out, Opaque> for F

Source§

type Step = OpaqueRefScanStep<F>

The concrete resolved ref-scan step type.
Source§

fn into_ref_scan_step(self, _registry: &Registry) -> Self::Step

Resolve Param state from the registry and produce a ref-scan step.
Source§

impl<In, Out, F: FnMut(&mut World, &In) -> Out + 'static> IntoRefStep<In, Out, Opaque> for F

Source§

type Step = OpaqueRefStep<F>

The concrete resolved step type.
Source§

fn into_ref_step(self, _registry: &Registry) -> Self::Step

Resolve Param state from the registry and produce a step.
Source§

impl<Acc, In, Out, F: FnMut(&mut World, &mut Acc, In) -> Out + 'static> IntoScanStep<Acc, In, Out, Opaque> for F

Source§

type Step = OpaqueScanStep<F>

The concrete resolved scan step type.
Source§

fn into_scan_step(self, _registry: &Registry) -> Self::Step

Resolve Param state from the registry and produce a scan step.
Source§

impl<In, Out, F: FnMut(&mut World, In) -> Out + 'static> IntoStep<In, Out, Opaque> for F

Source§

type Step = OpaqueStep<F>

The concrete resolved step type.
Source§

fn into_step(self, _registry: &Registry) -> Self::Step

Resolve Param state from the registry and produce a step.

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.