fix release

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

View File

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