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>;
#[inline(always)]
#[track_caller]
fn context(self, context: impl IntoContext) -> Self::Output {
self.into_result_how().map_err(#[inline(never)] move |e| e.context(context))
}
}
impl<T> Explain for Option<T> {
type Output = Result<T, How>;
impl<T> Explain for Option<T>
where
Option<T>: IntoResultHow,
{
type Output = Result<<Self as IntoResultHow>::T, How>;
#[inline(always)]
#[track_caller]
fn context(self, context: impl IntoContext) -> Self::Output {
// TODO: maybe add a feature for the extra "Option::None" context
match self {
Some(t) => Ok(t),
None => Err(How::new(context))
}
//self.into_result_how().map_err(#[inline(never)] move |e| e.context(context))
}
// TODO: maybe add a toggle for the extra "Option::None" context
//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
}
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 {
let mut b = f.debug_struct(std::any::type_name::<Self>());
let b = b

View File

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

View File

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