pub struct MeshRayCast<'w, 's> { /* private fields */ }Expand description
Add this ray casting SystemParam to your system to cast rays into the world with an
immediate-mode API. Call cast_ray to immediately perform a ray cast and get a result.
Under the hood, this is a collection of regular bevy queries, resources, and local parameters that are added to your system.
§Usage
The following system casts a ray into the world with the ray positioned at the origin, pointing in the X-direction, and returns a list of intersections:
fn ray_cast_system(mut ray_cast: MeshRayCast) {
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
let hits = ray_cast.cast_ray(ray, &MeshRayCastSettings::default());
}§Configuration
You can specify the behavior of the ray cast using MeshRayCastSettings. This allows you to filter out
entities, configure early-out behavior, and set whether the Visibility
of an entity should be considered.
fn ray_cast_system(mut ray_cast: MeshRayCast, foo_query: Query<(), With<Foo>>) {
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
// Only ray cast against entities with the `Foo` component.
let filter = |entity| foo_query.contains(entity);
// Never early-exit. Note that you can change behavior per-entity.
let early_exit_test = |_entity| false;
// Ignore the visibility of entities. This allows ray casting hidden entities.
let visibility = RayCastVisibility::Any;
let settings = MeshRayCastSettings::default()
.with_filter(&filter)
.with_early_exit_test(&early_exit_test)
.with_visibility(visibility);
// Cast the ray with the settings, returning a list of intersections.
let hits = ray_cast.cast_ray(ray, &settings);
}Implementations§
Source§impl<'w, 's> MeshRayCast<'w, 's>
impl<'w, 's> MeshRayCast<'w, 's>
Sourcepub fn cast_ray(
&mut self,
ray: Ray3d,
settings: &MeshRayCastSettings<'_>,
) -> &[(Entity, RayMeshHit)]
pub fn cast_ray( &mut self, ray: Ray3d, settings: &MeshRayCastSettings<'_>, ) -> &[(Entity, RayMeshHit)]
Casts the ray into the world and returns a sorted list of intersections, nearest first.
Examples found in repository?
examples/3d/mesh_ray_cast.rs (line 52)
45fn bounce_ray(mut ray: Ray3d, ray_cast: &mut MeshRayCast, gizmos: &mut Gizmos, color: Color) {
46 let mut intersections = Vec::with_capacity(MAX_BOUNCES + 1);
47 intersections.push((ray.origin, Color::srgb(30.0, 0.0, 0.0)));
48
49 for i in 0..MAX_BOUNCES {
50 // Cast the ray and get the first hit
51 let Some((_, hit)) = ray_cast
52 .cast_ray(ray, &MeshRayCastSettings::default())
53 .first()
54 else {
55 break;
56 };
57
58 // Draw the point of intersection and add it to the list
59 let brightness = 1.0 + 10.0 * (1.0 - i as f32 / MAX_BOUNCES as f32);
60 intersections.push((hit.point, Color::BLACK.mix(&color, brightness)));
61 gizmos.sphere(hit.point, 0.005, Color::BLACK.mix(&color, brightness * 2.0));
62
63 // Reflect the ray off of the surface
64 ray.direction = Dir3::new(ray.direction.reflect(hit.normal)).unwrap();
65 ray.origin = hit.point + ray.direction * 1e-6;
66 }
67 gizmos.linestrip_gradient(intersections);
68}More examples
examples/ui/render_ui_to_texture.rs (line 206)
174fn drive_diegetic_pointer(
175 mut cursor_last: Local<Vec2>,
176 mut raycast: MeshRayCast,
177 rays: Res<RayMap>,
178 cubes: Query<&Mesh3d, With<Cube>>,
179 ui_camera: Query<&Camera, With<Camera2d>>,
180 primary_window: Query<Entity, With<PrimaryWindow>>,
181 windows: Query<(Entity, &Window)>,
182 images: Res<Assets<Image>>,
183 manual_texture_views: Res<ManualTextureViews>,
184 mut window_events: MessageReader<WindowEvent>,
185 mut pointer_inputs: MessageWriter<PointerInput>,
186) -> Result {
187 // Get the size of the texture, so we can convert from dimensionless UV coordinates that span
188 // from 0 to 1, to pixel coordinates.
189 let target = ui_camera
190 .single()?
191 .target
192 .normalize(primary_window.single().ok())
193 .unwrap();
194 let target_info = target
195 .get_render_target_info(windows, &images, &manual_texture_views)
196 .unwrap();
197 let size = target_info.physical_size.as_vec2();
198
199 // Find raycast hits and update the virtual pointer.
200 let raycast_settings = MeshRayCastSettings {
201 visibility: RayCastVisibility::VisibleInView,
202 filter: &|entity| cubes.contains(entity),
203 early_exit_test: &|_| false,
204 };
205 for (_id, ray) in rays.iter() {
206 for (_cube, hit) in raycast.cast_ray(*ray, &raycast_settings) {
207 let position = size * hit.uv.unwrap();
208 if position != *cursor_last {
209 pointer_inputs.write(PointerInput::new(
210 CUBE_POINTER_ID,
211 Location {
212 target: target.clone(),
213 position,
214 },
215 PointerAction::Move {
216 delta: position - *cursor_last,
217 },
218 ));
219 *cursor_last = position;
220 }
221 }
222 }
223
224 // Pipe pointer button presses to the virtual pointer on the UI texture.
225 for window_event in window_events.read() {
226 if let WindowEvent::MouseButtonInput(input) = window_event {
227 let button = match input.button {
228 MouseButton::Left => PointerButton::Primary,
229 MouseButton::Right => PointerButton::Secondary,
230 MouseButton::Middle => PointerButton::Middle,
231 _ => continue,
232 };
233 let action = match input.state {
234 ButtonState::Pressed => PointerAction::Press(button),
235 ButtonState::Released => PointerAction::Release(button),
236 };
237 pointer_inputs.write(PointerInput::new(
238 CUBE_POINTER_ID,
239 Location {
240 target: target.clone(),
241 position: *cursor_last,
242 },
243 action,
244 ));
245 }
246 }
247
248 Ok(())
249}Trait Implementations§
Source§impl SystemParam for MeshRayCast<'_, '_>
impl SystemParam for MeshRayCast<'_, '_>
Source§type Item<'w, 's> = MeshRayCast<'w, 's>
type Item<'w, 's> = MeshRayCast<'w, 's>
The item type returned when constructing this system param.
The value of this associated type should be
Self, instantiated with new lifetimes. Read moreSource§fn init_state(world: &mut World) -> <MeshRayCast<'_, '_> as SystemParam>::State
fn init_state(world: &mut World) -> <MeshRayCast<'_, '_> as SystemParam>::State
Creates a new instance of this param’s
State.Source§fn init_access(
state: &<MeshRayCast<'_, '_> as SystemParam>::State,
system_meta: &mut SystemMeta,
component_access_set: &mut FilteredAccessSet,
world: &mut World,
)
fn init_access( state: &<MeshRayCast<'_, '_> as SystemParam>::State, system_meta: &mut SystemMeta, component_access_set: &mut FilteredAccessSet, world: &mut World, )
Registers any
World access used by this SystemParamSource§fn apply(
state: &mut <MeshRayCast<'_, '_> as SystemParam>::State,
system_meta: &SystemMeta,
world: &mut World,
)
fn apply( state: &mut <MeshRayCast<'_, '_> as SystemParam>::State, system_meta: &SystemMeta, world: &mut World, )
Applies any deferred mutations stored in this
SystemParam’s state.
This is used to apply Commands during ApplyDeferred.Source§fn queue(
state: &mut <MeshRayCast<'_, '_> as SystemParam>::State,
system_meta: &SystemMeta,
world: DeferredWorld<'_>,
)
fn queue( state: &mut <MeshRayCast<'_, '_> as SystemParam>::State, system_meta: &SystemMeta, world: DeferredWorld<'_>, )
Queues any deferred mutations to be applied at the next
ApplyDeferred.Source§unsafe fn validate_param<'w, 's>(
state: &'s mut <MeshRayCast<'_, '_> as SystemParam>::State,
_system_meta: &SystemMeta,
_world: UnsafeWorldCell<'w>,
) -> Result<(), SystemParamValidationError>
unsafe fn validate_param<'w, 's>( state: &'s mut <MeshRayCast<'_, '_> as SystemParam>::State, _system_meta: &SystemMeta, _world: UnsafeWorldCell<'w>, ) -> Result<(), SystemParamValidationError>
Source§unsafe fn get_param<'w, 's>(
state: &'s mut <MeshRayCast<'_, '_> as SystemParam>::State,
system_meta: &SystemMeta,
world: UnsafeWorldCell<'w>,
change_tick: Tick,
) -> <MeshRayCast<'_, '_> as SystemParam>::Item<'w, 's>
unsafe fn get_param<'w, 's>( state: &'s mut <MeshRayCast<'_, '_> as SystemParam>::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'w>, change_tick: Tick, ) -> <MeshRayCast<'_, '_> as SystemParam>::Item<'w, 's>
Creates a parameter to be passed into a
SystemParamFunction. Read moreimpl<'w, 's> ReadOnlySystemParam for MeshRayCast<'w, 's>where
Res<'w, Assets<Mesh>>: ReadOnlySystemParam,
Local<'s, Vec<(FloatOrd, (Entity, RayMeshHit))>>: ReadOnlySystemParam,
Local<'s, Vec<(Entity, RayMeshHit)>>: ReadOnlySystemParam,
Local<'s, Vec<(FloatOrd, Entity)>>: ReadOnlySystemParam,
Query<'w, 's, (&'static InheritedVisibility, &'static ViewVisibility, &'static Aabb, &'static GlobalTransform, Entity), Or<(With<Mesh3d>, With<Mesh2d>, With<SimplifiedMesh>)>>: ReadOnlySystemParam,
Query<'w, 's, (Option<&'static Mesh2d>, Option<&'static Mesh3d>, Option<&'static SimplifiedMesh>, Has<RayCastBackfaces>, &'static GlobalTransform), Or<(With<Mesh3d>, With<Mesh2d>, With<SimplifiedMesh>)>>: ReadOnlySystemParam,
Auto Trait Implementations§
impl<'w, 's> Freeze for MeshRayCast<'w, 's>
impl<'w, 's> !RefUnwindSafe for MeshRayCast<'w, 's>
impl<'w, 's> Send for MeshRayCast<'w, 's>
impl<'w, 's> Sync for MeshRayCast<'w, 's>
impl<'w, 's> Unpin for MeshRayCast<'w, 's>
impl<'w, 's> !UnwindSafe for MeshRayCast<'w, 's>
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
Return the
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
Causes
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
Causes
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
Causes
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
Causes
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
Causes
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
Causes
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
Causes
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
Causes
self to use its UpperHex implementation when
Debug-formatted.Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Create an instance of this type from an initialization function
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Converts this type into the system output type.
Source§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Pipes by value. This is generally the method you want to use. Read more
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
Borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
Mutably borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
Borrows
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
Mutably borrows
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
Borrows
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Convert from a type to another type.
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Convert from a type to another type.
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Immutable access to the
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
Mutable access to the
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
Immutable access to the
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
Mutable access to the
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Immutable access to the
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Mutable access to the
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
Calls
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
Calls
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
Calls
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
Calls
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
Calls
.tap_deref() only in debug builds, and is erased in release
builds.