Crates.io | eieio |
lib.rs | eieio |
version | 1.0.0 |
source | src |
created_at | 2020-05-17 20:30:38.075976 |
updated_at | 2020-05-17 20:30:38.075976 |
description | Error Implementing `Eq + Clone` replacing `std::io::Error` |
homepage | |
repository | https://github.com/kennytm/eieio |
max_upload_size | |
id | 242786 |
size | 6,870 |
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);
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.
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);