#io #error #eq #clone

eieio

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

1 stable release

1.0.0 May 17, 2020

#4 in #eq

Download history 605/week @ 2021-10-03 615/week @ 2021-10-10 865/week @ 2021-10-17 859/week @ 2021-10-24 940/week @ 2021-10-31 886/week @ 2021-11-07 2223/week @ 2021-11-14 1874/week @ 2021-11-21 2246/week @ 2021-11-28 2022/week @ 2021-12-05 1997/week @ 2021-12-12 1758/week @ 2021-12-19 1420/week @ 2021-12-26 1621/week @ 2022-01-02 1465/week @ 2022-01-09 1418/week @ 2022-01-16

6,129 downloads per month
Used in 3 crates (via pathos)

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

^