Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make error clonable #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

make error clonable #132

wants to merge 1 commit into from

Conversation

clouds56
Copy link

No description provided.

@sfackler
Copy link
Owner

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

@clouds56
Copy link
Author

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?

@sfackler
Copy link
Owner

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

@clouds56
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants