bincode icon indicating copy to clipboard operation
bincode copied to clipboard

ErrorKind Clone

Open BR03D opened this issue 2 years ago • 5 comments

Is there a reason for ErrorKind not implementing Clone? If not, can we make that happen?

BR03D avatar Jul 23 '22 08:07 BR03D

The new DecodeError does not implement it either - why?

BR03D avatar Jul 23 '22 09:07 BR03D

I'm assuming you mean EncodeError. This enum uses the following types that do not implement Clone:

We could implement Clone on DecodeError but I think it makes sense that both error types implement the same traits

VictorKoenders avatar Jul 23 '22 09:07 VictorKoenders

I was specifically referring to DecodeError. My application reads input from a TcpStream and in case of a DecodeError I want to attach that error to the return value (which i would like to be cloneable).

I dont see why both errors need to implement the same traits - imo if something can be Clone it should be.

BR03D avatar Jul 23 '22 11:07 BR03D

You could wrap the DecodeError in an Arc or Rc, that would give you a Clone implementation

VictorKoenders avatar Jul 23 '22 12:07 VictorKoenders

That is a good suggestion. I will implement it like this for now.

Still, if there is no reason for why it wouldnt be Clone, it should probably implement it.

BR03D avatar Jul 23 '22 13:07 BR03D

Turns out DecodeError should import std::io::Error, so I've added that in this PR.

If you want the two types mentioned above to implement Clone, please open up an issue on the rust issue tracker. We are open to implement any trait that core::cell::BorrowError and std::io::Error implement.

Feel free to re-open this issue when the traits implements change in a stable version of rust.

VictorKoenders avatar Aug 17 '22 08:08 VictorKoenders