Compare commits

..

No commits in common. "710eb48e0cd1ebeef2a119177a15daf9b6e54f07" and "60df0085b873a2435d149d8d62b098a4c50c4bf2" have entirely different histories.

4 changed files with 12 additions and 60 deletions

View File

@ -19,23 +19,21 @@ where
type Output = Result<<Self as IntoResultHow>::T, How>; type Output = Result<<Self as IntoResultHow>::T, How>;
#[inline(always)] #[inline(always)]
#[track_caller]
fn context(self, context: impl IntoContext) -> Self::Output { fn context(self, context: impl IntoContext) -> Self::Output {
self.into_result_how().map_err(#[inline(never)] move |e| e.context(context)) self.into_result_how().map_err(#[inline(never)] move |e| e.context(context))
} }
} }
impl<T> Explain for Option<T> { impl<T> Explain for Option<T>
type Output = Result<T, How>; where
Option<T>: IntoResultHow,
{
type Output = Result<<Self as IntoResultHow>::T, How>;
#[inline(always)] #[inline(always)]
#[track_caller]
fn context(self, context: impl IntoContext) -> Self::Output { fn context(self, context: impl IntoContext) -> Self::Output {
// TODO: maybe add a feature for the extra "Option::None" context // TODO: maybe add a toggle for the extra "Option::None" context
match self { //Err(How::new(context))
Some(t) => Ok(t), self.into_result_how().map_err(#[inline(never)] move |e| e.context(context))
None => Err(How::new(context))
}
//self.into_result_how().map_err(#[inline(never)] move |e| e.context(context))
}
} }
}

View File

@ -56,46 +56,6 @@ impl How {
self.0.classified self.0.classified
} }
pub fn location(&self) -> &Context {
// SAFETY: we only ever push values into context, and the constructor ensures that there
// are at least 2 values in context.
let o = self.0.context.get(0);
if cfg!(debug_assertions) {
o.unwrap()
} else {
#[allow(unsafe_code)]
unsafe { o.unwrap_unchecked() }
}
}
pub fn top(&self) -> &Context {
// SAFETY: we only ever push values into context, and the constructor ensures that there
// are at least 2 values in context.
let o = self.0.context.get(1);
if cfg!(debug_assertions) {
o.unwrap()
} else {
#[allow(unsafe_code)]
unsafe { o.unwrap_unchecked() }
}
}
pub fn bottom(&self) -> &Context {
// SAFETY: we only ever push values into context, and the constructor ensures that there
// are at least 2 values in context.
let o = self.0.context.iter().next_back();
if cfg!(debug_assertions) {
o.unwrap()
} else {
#[allow(unsafe_code)]
unsafe { o.unwrap_unchecked() }
}
}
pub fn into_context(self) -> impl Iterator<Item = Context> {
self.0.context.into_iter()
}
fn fmt_debug_alternate(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt_debug_alternate(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let mut b = f.debug_struct(std::any::type_name::<Self>()); let mut b = f.debug_struct(std::any::type_name::<Self>());
let b = b let b = b

View File

@ -27,10 +27,7 @@ where
fn into<E: std::error::Error>(e: E) -> How { fn into<E: std::error::Error>(e: E) -> How {
How::new(e.to_string()) How::new(e.to_string())
} }
match self { self.map_err(into)
Ok(t) => Ok(t),
Err(e) => Err(into(e))
}
} }
} }
@ -54,9 +51,6 @@ impl<T> IntoResultHow for Option<T> {
fn into() -> How { fn into() -> How {
How::new("Option::None") How::new("Option::None")
} }
match self { self.ok_or_else(into)
Some(t) => Ok(t),
None => Err(into())
}
} }
} }

View File

@ -1,5 +1,5 @@
#![doc = include_str!("../README.md")] #![doc = include_str!("../README.md")]
#![deny(unsafe_code)] #![forbid(unsafe_code)]
#![feature(backtrace)] #![feature(backtrace)]
mod sealed; mod sealed;