r2d2 icon indicating copy to clipboard operation
r2d2 copied to clipboard

make error clonable

Open clouds56 opened this issue 3 years ago • 4 comments

clouds56 avatar Aug 15 '22 16:08 clouds56

What's the rationale for this? Error types are generally not cloneable.

sfackler avatar Aug 15 '22 16:08 sfackler

Thanks for fast reply! Error type that not cloneable usually has a cloneable ErrorKind like std::io::ErrorKind. The error here could derive clone, so why not?

clouds56 avatar Aug 15 '22 16:08 clouds56

But how do you concretely want to use the clonability of those things?

sfackler avatar Aug 15 '22 16:08 sfackler

I'm using thiserror wrap errors, if r2d2::Error supports clone, I could use #[from]. The error would be cloned and send to log thread so it must derive Clone

#[derive(Debug, Clone, thiserror::Error)]
pub enum Error {
  #[error("pool error: {0}")]
  PoolArc(Arc<r2d2::Error>),
  #[error("pool error: {0}")]
  Pool(#[from] r2d2::Error),
}

You could see lots of error's (if not most) in std derives clone even they could have a large Vec<u8>, FromVecWithNulError, FromUtf8Error, fmt::Error, VarError, SystemTimeError, I think the policy is just derive Clone whenever possible. The std::io::Error is an exception since it couldn't.

clouds56 avatar Aug 15 '22 20:08 clouds56