fix release

This commit is contained in:
2023-10-11 12:25:13 -04:00
parent ad362d90d5
commit a607b4267c
2 changed files with 30 additions and 16 deletions

View File

@@ -18,27 +18,30 @@ pub struct Anything {
impl Anything { impl Anything {
#[track_caller] #[cfg_attr(debug_assertions,track_caller)]
pub fn new<T: DynError + 'static>(error: T) -> Anything { pub fn new<T: DynError + 'static>(error: T) -> Anything {
Anything { Anything {
error: Box::new(error), error: Box::new(error),
#[cfg(debug_assertions)]
origin: Location::caller(), origin: Location::caller(),
} }
} }
#[track_caller] #[cfg_attr(debug_assertions,track_caller)]
pub fn new_error<T: DynError + 'static>(error: T) -> Result<(), Anything> { pub fn new_error<T: DynError + 'static>(error: T) -> Result<(), Anything> {
Err(Anything { Err(Anything {
error: Box::new(error), error: Box::new(error),
#[cfg(debug_assertions)]
origin: Location::caller(), origin: Location::caller(),
}) })
} }
#[track_caller] #[cfg_attr(debug_assertions,track_caller)]
pub fn assert<T: DynError + 'static>(error_if_false: bool, error: T) -> Result<(), Anything> { pub fn assert<T: DynError + 'static>(error_if_false: bool, error: T) -> Result<(), Anything> {
if error_if_false { return Ok(()) } if error_if_false { return Ok(()) }
Err(Anything { Err(Anything {
error: Box::new(error), error: Box::new(error),
#[cfg(debug_assertions)]
origin: Location::caller(), origin: Location::caller(),
}) })
} }
@@ -58,34 +61,43 @@ impl Anything {
impl Display for Anything { impl Display for Anything {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, #[cfg(debug_assertions)]
let v = write!(f,
"[{}:{}:{}] {:?}", "[{}:{}:{}] {:?}",
self.origin.file(), self.origin.file(),
self.origin.line(), self.origin.line(),
self.origin.column(), self.origin.column(),
self.error.format() self.error.format()
) );
#[cfg(not(debug_assertions))]
let v = write!(f, "{:?}", self.error.format());
v
} }
} }
impl Debug for Anything { impl Debug for Anything {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, #[cfg(debug_assertions)]
"'{:?}'\n at {}:{}:{}", let v = write!(f,
self.error.format(), "'{:?}'\n at {}:{}:{}",
self.origin.file(), self.error.format(),
self.origin.line(), self.origin.file(),
self.origin.column() self.origin.line(),
) self.origin.column()
);
#[cfg(not(debug_assertions))]
let v = write!(f, "{:?}", self.error.format());
v
} }
} }
impl<T: DynError + 'static> From<T> for Anything { impl<T: DynError + 'static> From<T> for Anything {
#[track_caller] #[cfg_attr(debug_assertions,track_caller)]
fn from(value: T) -> Self { fn from(value: T) -> Self {
Anything { Anything {
error: Box::new(value), error: Box::new(value),
#[cfg(debug_assertions)]
origin: Location::caller(), origin: Location::caller(),
} }
} }

View File

@@ -1,3 +1,4 @@
use std::fs::File;
use anything::{Anything, Nothing}; use anything::{Anything, Nothing};
pub fn func_1() -> Result<(),Anything> { pub fn func_1() -> Result<(),Anything> {
@@ -15,9 +16,10 @@ pub fn func_3() -> Result<(),Nothing> {
Ok(()) Ok(())
} }
fn func_4() -> Anything { fn func_4() -> Result<(), Anything> {
let a= std::io::Error::last_os_error(); let _ = Anything::from(File::open("afsfasfd").unwrap_err());
Anything::from(a) let _ = File::open("afsfasfd")?;
Ok(())
} }
fn func_5() -> Result<(), Anything> { fn func_5() -> Result<(), Anything> {