Skip to content

Commit

Permalink
#104 get rid of Clone constraints.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zefick committed Apr 30, 2023
1 parent f1e4340 commit 97b3033
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/ctors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use crate::Map;
use std::mem::MaybeUninit;

impl<K: Clone + PartialEq, V: Clone, const N: usize> Default for Map<K, V, N> {
impl<K: PartialEq, V, const N: usize> Default for Map<K, V, N> {
/// Make a default empty [`Map`].
#[inline]
#[must_use]
Expand All @@ -30,7 +30,7 @@ impl<K: Clone + PartialEq, V: Clone, const N: usize> Default for Map<K, V, N> {
}
}

impl<K: Clone + PartialEq, V: Clone, const N: usize> Map<K, V, N> {
impl<K: PartialEq, V, const N: usize> Map<K, V, N> {
/// Make it.
///
/// The size of the map is defined by the generic argument. For example,
Expand All @@ -48,7 +48,7 @@ impl<K: Clone + PartialEq, V: Clone, const N: usize> Map<K, V, N> {
}
}

impl<K: Clone + PartialEq, V: Clone, const N: usize> Drop for Map<K, V, N> {
impl<K: PartialEq, V, const N: usize> Drop for Map<K, V, N> {
fn drop(&mut self) {
for i in 0..self.next {
unsafe {
Expand Down
4 changes: 2 additions & 2 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ use crate::Map;
use std::fmt;
use std::fmt::{Debug, Display, Formatter};

impl<K: Clone + PartialEq + Display, V: Clone + Display, const N: usize> Display for Map<K, V, N> {
impl<K: PartialEq + Display, V: Display, const N: usize> Display for Map<K, V, N> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
<&Self as Debug>::fmt(&self, f)
}
}

impl<K: Clone + PartialEq + Display, V: Clone + Display, const N: usize> Debug for Map<K, V, N> {
impl<K: PartialEq + Display, V: Display, const N: usize> Debug for Map<K, V, N> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
let mut parts = vec![];
for (k, v) in self.iter() {
Expand Down
4 changes: 2 additions & 2 deletions src/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use crate::Map;

impl<K: Clone + PartialEq, V: Clone + PartialEq, const N: usize> PartialEq for Map<K, V, N> {
impl<K: PartialEq, V: PartialEq, const N: usize> PartialEq for Map<K, V, N> {
/// Two maps can be compared.
///
/// For example:
Expand All @@ -44,7 +44,7 @@ impl<K: Clone + PartialEq, V: Clone + PartialEq, const N: usize> PartialEq for M
}
}

impl<K: Clone + Eq, V: Clone + Eq, const N: usize> Eq for Map<K, V, N> {}
impl<K: Eq, V: Eq, const N: usize> Eq for Map<K, V, N> {}

#[test]
fn compares_two_maps() {
Expand Down
4 changes: 2 additions & 2 deletions src/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use crate::Map;

impl<K: Clone + PartialEq, V: Clone, const N: usize> FromIterator<(K, V)> for Map<K, V, N> {
impl<K: PartialEq, V, const N: usize> FromIterator<(K, V)> for Map<K, V, N> {
#[inline]
#[must_use]
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
Expand All @@ -32,7 +32,7 @@ impl<K: Clone + PartialEq, V: Clone, const N: usize> FromIterator<(K, V)> for Ma
}
}

impl<K: Clone + PartialEq, V: Clone, const N: usize> From<[(K, V); N]> for Map<K, V, N> {
impl<K: PartialEq, V, const N: usize> From<[(K, V); N]> for Map<K, V, N> {
#[inline]
#[must_use]
fn from(arr: [(K, V); N]) -> Self {
Expand Down
10 changes: 3 additions & 7 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ use crate::Map;
use std::borrow::Borrow;
use std::ops::{Index, IndexMut};

impl<K: Clone + Eq + Borrow<Q>, Q: Eq + ?Sized, V: Clone, const N: usize> Index<&Q>
for Map<K, V, N>
{
impl<K: Eq + Borrow<Q>, Q: Eq + ?Sized, V, const N: usize> Index<&Q> for Map<K, V, N> {
type Output = V;

#[inline]
Expand All @@ -34,9 +32,7 @@ impl<K: Clone + Eq + Borrow<Q>, Q: Eq + ?Sized, V: Clone, const N: usize> Index<
}
}

impl<K: Clone + Eq + Borrow<Q>, Q: Eq + ?Sized, V: Clone, const N: usize> IndexMut<&Q>
for Map<K, V, N>
{
impl<K: Eq + Borrow<Q>, Q: Eq + ?Sized, V, const N: usize> IndexMut<&Q> for Map<K, V, N> {
#[inline]
#[must_use]
fn index_mut(&mut self, key: &Q) -> &mut V {
Expand Down Expand Up @@ -68,7 +64,7 @@ fn wrong_index() -> () {
}

#[cfg(test)]
#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(PartialEq, Eq)]
struct Container {
pub t: i32,
}
Expand Down
6 changes: 3 additions & 3 deletions src/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use crate::{IntoIter, Iter, IterMut, Map};

impl<K: PartialEq + Clone, V: Clone, const N: usize> Map<K, V, N> {
impl<K: PartialEq, V, const N: usize> Map<K, V, N> {
/// Make an iterator over all pairs.
#[inline]
#[must_use]
Expand All @@ -43,7 +43,7 @@ impl<K: PartialEq + Clone, V: Clone, const N: usize> Map<K, V, N> {
}
}

impl<'a, K: Clone, V: Clone, const N: usize> Iterator for Iter<'a, K, V, N> {
impl<'a, K, V, const N: usize> Iterator for Iter<'a, K, V, N> {
type Item = (&'a K, &'a V);

#[inline]
Expand All @@ -60,7 +60,7 @@ impl<'a, K: Clone, V: Clone, const N: usize> Iterator for Iter<'a, K, V, N> {
}
}

impl<'a, K: Clone, V: Clone> Iterator for IterMut<'a, K, V> {
impl<'a, K, V> Iterator for IterMut<'a, K, V> {
type Item = (&'a K, &'a mut V);

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ use std::mem::MaybeUninit;
/// into it, it simply panics. Moreover, in the "release" mode it doesn't panic,
/// but its behaviour is undefined. In the "release" mode all boundary checks
/// are disabled, for the sake of higher performance.
pub struct Map<K: Clone + PartialEq, V: Clone, const N: usize> {
pub struct Map<K: PartialEq, V, const N: usize> {
/// The next available pair in the array.
next: usize,
/// The fixed-size array of key-value pairs.
Expand Down
8 changes: 3 additions & 5 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use crate::Map;
use std::borrow::Borrow;

impl<K: PartialEq + Clone, V: Clone, const N: usize> Map<K, V, N> {
impl<K: PartialEq, V, const N: usize> Map<K, V, N> {
/// Get its total capacity.
#[inline]
#[must_use]
Expand Down Expand Up @@ -198,7 +198,8 @@ impl<K: PartialEq + Clone, V: Clone, const N: usize> Map<K, V, N> {
#[inline]
pub fn remove_entry<Q: PartialEq + ?Sized>(&mut self, k: &Q) -> Option<(K, V)>
where
K: Borrow<Q>,
K: Borrow<Q> + Clone,
V: Clone,
{
for i in 0..self.next {
if let Some(p) = self.item(i) {
Expand Down Expand Up @@ -330,9 +331,6 @@ fn insert_composite() {
assert_eq!(0, m.into_iter().next().unwrap().1.r.len());
}

#[derive(Clone, Copy)]
struct Bar {}

#[test]
fn large_map_in_heap() {
let m: Box<Map<u64, [u64; 10], 10>> = Box::new(Map::new());
Expand Down
12 changes: 5 additions & 7 deletions src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::fmt::Formatter;
use std::marker::PhantomData;

impl<K: Clone + PartialEq + Serialize, V: Clone + Serialize, const N: usize> Serialize
for Map<K, V, N>
{
impl<K: PartialEq + Serialize, V: Serialize, const N: usize> Serialize for Map<K, V, N> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
Expand All @@ -42,8 +40,8 @@ impl<K: Clone + PartialEq + Serialize, V: Clone + Serialize, const N: usize> Ser

struct Vi<K, V, const N: usize>(PhantomData<K>, PhantomData<V>);

impl<'de, K: Clone + PartialEq + Deserialize<'de>, V: Clone + Deserialize<'de>, const N: usize>
Visitor<'de> for Vi<K, V, N>
impl<'de, K: PartialEq + Deserialize<'de>, V: Deserialize<'de>, const N: usize> Visitor<'de>
for Vi<K, V, N>
{
type Value = Map<K, V, N>;

Expand All @@ -63,8 +61,8 @@ impl<'de, K: Clone + PartialEq + Deserialize<'de>, V: Clone + Deserialize<'de>,
}
}

impl<'de, K: Clone + PartialEq + Deserialize<'de>, V: Clone + Deserialize<'de>, const N: usize>
Deserialize<'de> for Map<K, V, N>
impl<'de, K: PartialEq + Deserialize<'de>, V: Deserialize<'de>, const N: usize> Deserialize<'de>
for Map<K, V, N>
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down

0 comments on commit 97b3033

Please sign in to comment.