Skip to content

Instantly share code, notes, and snippets.

@vlad9486
Last active October 24, 2018 21:41
Show Gist options
  • Save vlad9486/be61236345adb5ad281595881e1a505a to your computer and use it in GitHub Desktop.
Save vlad9486/be61236345adb5ad281595881e1a505a to your computer and use it in GitHub Desktop.
#[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