2021-11-05 19:35:26 +00:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
pub struct OkInner;
|
|
|
|
#[allow(non_upper_case_globals)]
|
2021-11-11 13:29:43 +00:00
|
|
|
pub const _Ok: Prism<OkInner> = Prism(OkInner);
|
2021-11-05 19:35:26 +00:00
|
|
|
impl<T, E> PrismPreview<Result<T, E>> for OkInner {
|
|
|
|
type Field = T;
|
|
|
|
|
2021-11-11 14:47:55 +00:00
|
|
|
fn preview(&self, thing: Result<T, E>) -> Option<Self::Field> {
|
2021-11-05 19:35:26 +00:00
|
|
|
thing.ok()
|
|
|
|
}
|
2021-11-11 14:47:55 +00:00
|
|
|
fn review(&self, thing: Self::Field) -> Result<T, E> {
|
2021-11-05 19:35:26 +00:00
|
|
|
Ok(thing)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
pub struct ErrInner;
|
|
|
|
#[allow(non_upper_case_globals)]
|
2021-11-11 13:29:43 +00:00
|
|
|
pub const _Err: Prism<ErrInner> = Prism(ErrInner);
|
2021-11-05 19:35:26 +00:00
|
|
|
|
|
|
|
impl<T, E> PrismPreview<Result<T, E>> for ErrInner {
|
|
|
|
type Field = E;
|
|
|
|
|
2021-11-11 14:47:55 +00:00
|
|
|
fn preview(&self, thing: Result<T, E>) -> Option<Self::Field> {
|
2021-11-05 19:35:26 +00:00
|
|
|
thing.err()
|
|
|
|
}
|
2021-11-11 14:47:55 +00:00
|
|
|
fn review(&self, thing: Self::Field) -> Result<T, E> {
|
2021-11-05 19:35:26 +00:00
|
|
|
Err(thing)
|
|
|
|
}
|
|
|
|
}
|