Skip to content

Commit

Permalink
#18 less of a Copy
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Apr 24, 2023
1 parent 57fdad6 commit f82eee4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
8 changes: 2 additions & 6 deletions src/debug.rs
Expand Up @@ -22,17 +22,13 @@ use crate::Map;
use std::fmt;
use std::fmt::{Debug, Display, Formatter};

impl<K: Copy + PartialEq + Display, V: Clone + Copy + Display, const N: usize> Display
for Map<K, V, N>
{
impl<K: Clone + PartialEq + Display, V: Clone + 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: Copy + PartialEq + Display, V: Clone + Copy + Display, const N: usize> Debug
for Map<K, V, N>
{
impl<K: Clone + PartialEq + Display, V: Clone + 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
22 changes: 7 additions & 15 deletions src/serialization.rs
Expand Up @@ -25,29 +25,25 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::fmt::Formatter;
use std::marker::PhantomData;

impl<K: Copy + PartialEq + Serialize, V: Clone + Copy + Serialize, const N: usize> Serialize
impl<K: Clone + PartialEq + Serialize, V: Clone + Serialize, const N: usize> Serialize
for Map<K, V, N>
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut map = serializer.serialize_map(Some(self.len()))?;
for (a, v) in self {
map.serialize_entry(&a, &v)?;
for (a, v) in self.iter() {
map.serialize_entry(a, v)?;
}
map.end()
}
}

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

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

Expand All @@ -67,12 +63,8 @@ impl<
}
}

impl<
'de,
K: Copy + PartialEq + Deserialize<'de>,
V: Clone + Copy + Deserialize<'de>,
const N: usize,
> Deserialize<'de> for Map<K, V, N>
impl<'de, K: Clone + PartialEq + Deserialize<'de>, V: Clone + 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 f82eee4

Please sign in to comment.