pub struct RunOnDrop<T, F>where
F: FnOnce(T),{ /* private fields */ }
Available on crate feature
on_drop
only.Expand description
A wrapper type that runs a closure at the end of the scope.
This takes both a value and a closure(that takes the value as a parameter), allowing you to access the value before the closure runs.
§Example
use core_extensions::RunOnDrop;
fn main() {
let mut guard = RunOnDrop::new("Hello".to_string(), |string|{
assert_eq!(string, "Hello, world!");
});
assert_eq!(guard.get(), "Hello");
guard.get_mut().push_str(", world!");
}
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<T, F> Freeze for RunOnDrop<T, F>
impl<T, F> RefUnwindSafe for RunOnDrop<T, F>where
T: RefUnwindSafe,
F: RefUnwindSafe,
impl<T, F> Send for RunOnDrop<T, F>
impl<T, F> Sync for RunOnDrop<T, F>
impl<T, F> Unpin for RunOnDrop<T, F>
impl<T, F> UnwindSafe for RunOnDrop<T, F>where
T: UnwindSafe,
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> AsPhantomData for Twhere
T: ?Sized,
impl<T> AsPhantomData for Twhere
T: ?Sized,
Source§fn as_phantom(&self) -> PhantomData<Self>
fn as_phantom(&self) -> PhantomData<Self>
Available on crate feature
phantom
only.Gets a
PhantomData<Self>
. Read moreSource§fn as_phantom_covariant(&self) -> PhantomData<fn() -> Self>
fn as_phantom_covariant(&self) -> PhantomData<fn() -> Self>
Available on crate feature
phantom
only.Gets a
PhantomData<fn() -> Self>
, a covariant PhantomData
.Source§fn as_phantom_contra(&self) -> PhantomData<fn(Self)>
fn as_phantom_contra(&self) -> PhantomData<fn(Self)>
Available on crate feature
phantom
only.Gets a
PhantomData<fn(Self)>
, a contravariant PhantomData
.Source§fn as_phantom_invariant(&self) -> PhantomData<fn(Self) -> Self>
fn as_phantom_invariant(&self) -> PhantomData<fn(Self) -> Self>
Available on crate feature
phantom
only.Gets a
PhantomData<fn(Self) -> Self>
, an invariant PhantomData
.Source§const PHANTOM: PhantomData<Self> = PhantomData
const PHANTOM: PhantomData<Self> = PhantomData
Available on crate feature
phantom
only.Gets a
PhantomData<Self>
. Read moreSource§const PHANTOM_COVARIANT: PhantomData<fn() -> Self> = PhantomData
const PHANTOM_COVARIANT: PhantomData<fn() -> Self> = PhantomData
Available on crate feature
phantom
only.Source§const PHANTOM_CONTRA: PhantomData<fn(Self)> = PhantomData
const PHANTOM_CONTRA: PhantomData<fn(Self)> = PhantomData
Available on crate feature
phantom
only.Source§const PHANTOM_INVARIANT: PhantomData<fn(Self) -> Self> = PhantomData
const PHANTOM_INVARIANT: PhantomData<fn(Self) -> Self> = PhantomData
Available on crate feature
phantom
only.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> CallExt for Twhere
T: ?Sized,
impl<T> CallExt for Twhere
T: ?Sized,
Source§fn ref_call<P>(&self, params: P) -> Self::Returnswhere
Self: CallRef<P>,
fn ref_call<P>(&self, params: P) -> Self::Returnswhere
Self: CallRef<P>,
Available on crate feature
callable
only.For calling
CallRef::ref_call_
,
with the ability to specify the types of the arguments.. Read moreSource§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
Source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
Available on crate feature
self_ops
only.Emulates the pipeline operator, allowing method syntax in more places. Read more
Source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
Available on crate feature
self_ops
only.The same as
piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read moreSource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
Available on crate feature
self_ops
only.The same as
piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
.Source§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
Available on crate feature
self_ops
only.Mutates self using a closure taking self by mutable reference,
passing it along the method chain. Read more
Source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
Available on crate feature
self_ops
only.Observes the value of self, passing it along unmodified.
Useful in long method chains. Read more
Source§fn as_ref_<T: ?Sized>(&self) -> &Twhere
Self: AsRef<T>,
fn as_ref_<T: ?Sized>(&self) -> &Twhere
Self: AsRef<T>,
Available on crate feature
self_ops
only.Performs a reference to reference conversion with
AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read moreSource§impl<T> TypeIdentity for Twhere
T: ?Sized,
impl<T> TypeIdentity for Twhere
T: ?Sized,
Source§fn into_type(self) -> Self::Type
fn into_type(self) -> Self::Type
Available on crate feature
type_identity
only.Converts a value back to the original type.
Source§fn as_type(&self) -> &Self::Type
fn as_type(&self) -> &Self::Type
Available on crate feature
type_identity
only.Converts a reference back to the original type.
Source§fn as_type_mut(&mut self) -> &mut Self::Type
fn as_type_mut(&mut self) -> &mut Self::Type
Available on crate feature
type_identity
only.Converts a mutable reference back to the original type.
Source§fn into_type_box(self: Box<Self>) -> Box<Self::Type>
fn into_type_box(self: Box<Self>) -> Box<Self::Type>
Available on crate features
type_identity
and alloc
only.Converts a box back to the original type.
Source§fn into_type_arc(self: Arc<Self>) -> Arc<Self::Type>
fn into_type_arc(self: Arc<Self>) -> Arc<Self::Type>
Available on crate features
type_identity
and alloc
only.Converts an Arc back to the original type. Read more
Source§fn into_type_rc(self: Rc<Self>) -> Rc<Self::Type>
fn into_type_rc(self: Rc<Self>) -> Rc<Self::Type>
Available on crate features
type_identity
and alloc
only.Converts an Rc back to the original type. Read more
Source§fn from_type(this: Self::Type) -> Self
fn from_type(this: Self::Type) -> Self
Available on crate feature
type_identity
only.Converts a value back to the original type.
Source§fn from_type_ref(this: &Self::Type) -> &Self
fn from_type_ref(this: &Self::Type) -> &Self
Available on crate feature
type_identity
only.Converts a reference back to the original type.
Source§fn from_type_mut(this: &mut Self::Type) -> &mut Self
fn from_type_mut(this: &mut Self::Type) -> &mut Self
Available on crate feature
type_identity
only.Converts a mutable reference back to the original type.
Source§fn from_type_box(this: Box<Self::Type>) -> Box<Self>
fn from_type_box(this: Box<Self::Type>) -> Box<Self>
Available on crate features
type_identity
and alloc
only.Converts a box back to the original type.