Closed
Description
So. I hope I'm misreading the code or reading at the wrong place. But…
If I can read https://doc.rust-lang.org/src/alloc/borrow.rs.html#159-182 correctly, the implementation of Clone for Cow is like this:
fn clone(&self) -> Cow<'a, B> {
match *self {
Borrowed(b) => Borrowed(b),
Owned(ref o) => {
let b: &B = o.borrow();
Owned(b.to_owned())
}
}
}
So this copies the data when the Cow is copied.
I think it should instead be written like this:
fn clone(&self) -> Cow<'a, B> {
match *self {
Borrowed(b) => Borrowed(b),
Owned(ref o) => Borrowed(o.borrow()),
}
}
(and a similar fix for clone_from
)
If I didn't misunderstand the code or its purpose, I can try to write up a PR to fix this.
(and plz gimme kudos for the clickbait title)