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

get rid of Clone trait for V and K wherewer possible #104

Closed
Zefick opened this issue Apr 30, 2023 · 1 comment
Closed

get rid of Clone trait for V and K wherewer possible #104

Zefick opened this issue Apr 30, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Zefick
Copy link
Contributor

Zefick commented Apr 30, 2023

Cloning is not required for the core functionality of micromap as well as for HashMap, and this restriction can be removed from the many implementation blocks. The Clone constraint can be added separately for functions that really need it. E.g. that's how remove_entry's declaration may look like:

pub fn remove_entry<Q: PartialEq + ?Sized>(&mut self, k: &Q) -> Option<(K, V)>
where
    K: Borrow<Q> + Clone,
    V: Clone,
{
    ...
}

It's only function in the main block that need Clone, but I believe it's possible to remove it from there too although this is not necessary.

Impl blocks like IntoIterator for &Map and Clone for Map must declare its own constraint if it needed. They actually do it anyway and there is no need to change anything there.

If K or V not deriving Clone then it will not be possible to call into_iter() and clone() but all other methods shoud work.

In fact, standard HashMap are not required Clone for into_iter() neither it to be called by reference nor by value and it is the difference between it and the micromap. IntoIterator for &HashMap returns references to its elements and IntoIterator for HashMap just comsumes a map so it's not accessible anymore.

Zefick added a commit to Zefick/micromap that referenced this issue Apr 30, 2023
@yegor256 yegor256 added the bug Something isn't working label Apr 30, 2023
@yegor256
Copy link
Owner

yegor256 commented May 3, 2023

fixed

@yegor256 yegor256 closed this as completed May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants