Last active
October 24, 2018 21:41
-
-
Save vlad9486/be61236345adb5ad281595881e1a505a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Copy, Clone, Debug, Eq, PartialEq)] | |
pub struct Danger<T> { | |
value: T, | |
} | |
impl<T> Danger<T> { | |
pub fn block<A>(a: A, f: unsafe fn(A) -> T) -> Self { | |
Danger { | |
value: unsafe { f(a) }, | |
} | |
} | |
pub unsafe fn unwrap(self) -> T { | |
self.value | |
} | |
pub fn id(self) -> Self { | |
Danger::block(self, Self::unwrap) | |
} | |
pub fn and_then<F, U>(self, f: F) -> Danger<U> | |
where | |
F: FnOnce(T) -> Danger<U>, | |
{ | |
f(self.value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment