mirror of
https://github.com/haraldh/chainerror.git
synced 2025-01-30 16:46:42 +01:00
fix: clippy
Signed-off-by: Harald Hoyer <harald@hoyer.xyz>
This commit is contained in:
parent
05085229be
commit
d60cdf9cdb
|
@ -18,7 +18,7 @@ fn func3() -> Result<(), Box<dyn Error + Send + Sync>> {
|
|||
derive_str_context!(Func2Error);
|
||||
|
||||
fn func2() -> ChainResult<(), Func2Error> {
|
||||
func3().context(Func2Error(format!("func2 error: calling func3")))?;
|
||||
func3().context(Func2Error("func2 error: calling func3".to_string()))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ pub mod mycrate {
|
|||
|
||||
let filename = "bar.txt";
|
||||
|
||||
do_some_io(filename).map_context(|e| ErrorKind::from_io_error(&e, filename.into()))?;
|
||||
do_some_io(filename).map_context(|e| ErrorKind::from_io_error(e, filename.into()))?;
|
||||
do_some_io(filename).map_context(|_| ErrorKind::IO(filename.into()))?;
|
||||
do_some_io(filename).map_context(|e| ErrorKind::from(e))?;
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ fn func2() -> Result<(), Box<dyn Error + Send + Sync>> {
|
|||
}
|
||||
|
||||
fn func1() -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
func2().context(format!("func1 error"))?;
|
||||
func2().context("func1 error")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ fn func2() -> Result<(), Box<dyn Error + Send + Sync>> {
|
|||
derive_str_context!(Func1Error);
|
||||
|
||||
fn func1() -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
func2().context(Func1Error(format!("func1 error")))?;
|
||||
func2().context(Func1Error("func1 error".to_string()))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ derive_str_context!(Func1ErrorFunc2);
|
|||
derive_str_context!(Func1ErrorIO);
|
||||
|
||||
fn func1() -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
func2().context(Func1ErrorFunc2(format!("func1 error calling func2")))?;
|
||||
func2().context(Func1ErrorFunc2("func1 error calling func2".to_string()))?;
|
||||
let filename = "bar.txt";
|
||||
do_some_io().context(Func1ErrorIO(format!("Error reading '{}'", filename)))?;
|
||||
Ok(())
|
||||
|
|
|
@ -103,7 +103,6 @@
|
|||
//! Read the [Tutorial](https://haraldh.github.io/chainerror/tutorial1.html)
|
||||
|
||||
#![deny(clippy::all)]
|
||||
#![deny(clippy::integer_arithmetic)]
|
||||
#![allow(clippy::needless_doctest_main)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
|
@ -198,7 +197,9 @@ impl<T: 'static + Display + Debug> ChainError<T> {
|
|||
/// ```
|
||||
#[inline]
|
||||
pub fn find_cause<U: Error + 'static>(&self) -> Option<&U> {
|
||||
self.iter().filter_map(Error::downcast_ref::<U>).next()
|
||||
self.iter()
|
||||
.filter_map(<dyn Error>::downcast_ref::<U>)
|
||||
.next()
|
||||
}
|
||||
|
||||
/// Find the first error cause of type `ChainError<U>`, if any exists
|
||||
|
@ -220,7 +221,7 @@ impl<T: 'static + Display + Debug> ChainError<T> {
|
|||
#[inline]
|
||||
pub fn find_chain_cause<U: Error + 'static>(&self) -> Option<&ChainError<U>> {
|
||||
self.iter()
|
||||
.filter_map(Error::downcast_ref::<ChainError<U>>)
|
||||
.filter_map(<dyn Error>::downcast_ref::<ChainError<U>>)
|
||||
.next()
|
||||
}
|
||||
|
||||
|
@ -428,7 +429,7 @@ impl<U: 'static + Display + Debug> ChainErrorDown for ChainError<U> {
|
|||
#[allow(clippy::cast_ptr_alignment)]
|
||||
unsafe {
|
||||
#[allow(trivial_casts)]
|
||||
Some(&*(self as *const dyn Error as *const &ChainError<T>))
|
||||
Some(*(self as *const dyn Error as *const &ChainError<T>))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -18,13 +18,13 @@ fn test_iter() -> Result<(), Box<dyn Error + Send + Sync>> {
|
|||
let mut res = String::new();
|
||||
|
||||
for e in err.iter() {
|
||||
write!(res, "{}", e.to_string())?;
|
||||
write!(res, "{}", e)?;
|
||||
}
|
||||
assert_eq!(res, "654321entity not found");
|
||||
|
||||
let io_error: Option<&io::Error> = err
|
||||
.iter()
|
||||
.filter_map(Error::downcast_ref::<io::Error>)
|
||||
.filter_map(<dyn Error>::downcast_ref::<io::Error>)
|
||||
.next();
|
||||
|
||||
assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound);
|
||||
|
@ -50,7 +50,7 @@ fn test_iter() -> Result<(), Box<dyn Error + Send + Sync>> {
|
|||
|
||||
let io_error: Option<&io::Error> = err
|
||||
.iter()
|
||||
.filter_map(Error::downcast_ref::<io::Error>)
|
||||
.filter_map(<dyn Error>::downcast_ref::<io::Error>)
|
||||
.next();
|
||||
|
||||
assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound);
|
||||
|
@ -88,7 +88,7 @@ fn test_root_cause() -> Result<(), Box<dyn Error + Send + Sync>> {
|
|||
let err = err.err().unwrap();
|
||||
|
||||
let err: Option<&(dyn std::error::Error + 'static)> = err.root_cause();
|
||||
let io_error: Option<&io::Error> = err.and_then(Error::downcast_ref::<io::Error>);
|
||||
let io_error: Option<&io::Error> = err.and_then(<dyn Error>::downcast_ref::<io::Error>);
|
||||
|
||||
assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound);
|
||||
|
||||
|
|
Loading…
Reference in a new issue