apply trait
This commit is contained in:
1 parent
fc6caf0de6
commit
3dcb61021f
1 file changed
+20
@@ -1,5 +1,25 @@
|
||||
use core::convert::Infallible;
|
||||
|
||||
pub trait Apply: Sized {
|
||||
fn apply<U, F>(self, f: F) -> U
|
||||
where
|
||||
F: FnOnce(Self) -> U;
|
||||
}
|
||||
|
||||
impl<T> Apply for T
|
||||
where
|
||||
T: Sized,
|
||||
{
|
||||
#[inline]
|
||||
#[must_use]
|
||||
fn apply<U, F>(self, f: F) -> U
|
||||
where
|
||||
F: FnOnce(Self) -> U
|
||||
{
|
||||
f(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// Consumes an element of type `Infallible` and produces an element of any type `T`. This is
|
||||
/// possible because `Infallible` has no elements and thus this function can never be called, so
|
||||
/// the statement "for any given type `T`, whenever this function returns, it returns an element of
|
||||
|
||||
Reference in new issue
Block a user