Skip to content

Conversation

@GnomedDev
Copy link
Contributor

I couldn't see why Clone is implemented weirdly, so I implemented it just in terms of Vec::clone. This also adds clone_from, which is why I didn't use the derive macro.

let mut data = Vec::with_capacity(self.meta.iter().map(|m| m.len).sum());
let mut meta = Vec::with_capacity(self.meta.len());

for bytes in self.iter() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this was done this way was to trim on clones - which is fine imo because Clone does not require a byte-for-byte copy. This is unrelated by my main concern with this function was actually whether i should bother making an extend_from_slice_unchecked lol.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to violate the principle of least surprise. I wouldn't assume a clone implementation to trim

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair, but I wouldn't expect a clone of something to also clone useless bytes.

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.

2 participants