#io-error #error #io #eq #clone

eieio

Error Implementing Eq + Clone replacing std::io::Error

1 stable release

1.0.0 May 17, 2020

#2010 in Rust patterns

Download history 4404/week @ 2024-03-14 4951/week @ 2024-03-21 4844/week @ 2024-03-28 6290/week @ 2024-04-04 5447/week @ 2024-04-11 5423/week @ 2024-04-18 4713/week @ 2024-04-25 5368/week @ 2024-05-02 5517/week @ 2024-05-09 6927/week @ 2024-05-16 4678/week @ 2024-05-23 4584/week @ 2024-05-30 4620/week @ 2024-06-06 4913/week @ 2024-06-13 4857/week @ 2024-06-20 3586/week @ 2024-06-27

18,932 downloads per month
Used in 7 crates (2 directly)

MIT license

6KB
114 lines

eieio — Error Implementing Eq + Clone replacing std::io::Error

eieio::Error is a replacement of std::io::Error which implements Eq + Clone. This type is intended as a "source" of other errors where a derived Eq + Clone implemented is desired.

// Constructs a standard io::Error...
let ioe = std::fs::read_dir("/dev/null").unwrap_err();

// Converts into an Eq + Clone error
let e1 = eieio::Error::from(ioe);
let e2 = e1.clone();
assert_eq!(e1, e2);

Clone

eieio::Error stores custom errors in an Arc rather than a Box to allow universal cloning.

Conversion from std::io::Error to eieio::Error may need to perform a copy of the entire custom error.

Equality

eieio::Error uses Arc::ptr_eq to compare equality of custom errors.

If the custom error carried by the original std::io::Error itself implements Eq, that custom equality is ignored:

use std::io::ErrorKind;

let e1 = eieio::Error::new(ErrorKind::Other, Box::from("foo"));
let e2 = eieio::Error::new(ErrorKind::Other, Box::from("foo"));
assert_ne!(e1, e2);

No runtime deps