Skip to content

Commit

Permalink
fix: add Copy trait bound to struct
Browse files Browse the repository at this point in the history
  • Loading branch information
vmx committed Mar 30, 2020
1 parent 8090040 commit d980eac
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions src/cid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub type Cid = CidGeneric<Code, Codec>;
#[derive(PartialEq, Eq, Clone, Debug, PartialOrd, Ord)]
pub struct CidGeneric<T, U>
where
T: Into<u64> + TryFrom<u64>,
U: Into<u64> + TryFrom<u64>,
T: Into<u64> + TryFrom<u64> + Copy,
U: Into<u64> + TryFrom<u64> + Copy,
{
/// The version of CID.
version: Version,
Expand All @@ -30,9 +30,9 @@ where

impl<T, U> CidGeneric<T, U>
where
T: Into<u64> + TryFrom<u64>,
T: Into<u64> + TryFrom<u64> + Copy,
<T as TryFrom<u64>>::Error: std::fmt::Debug,
U: Into<u64> + TryFrom<u64>,
U: Into<u64> + TryFrom<u64> + Copy,
<U as TryFrom<u64>>::Error: std::fmt::Debug,
{
/// Create a new CIDv0.
Expand Down Expand Up @@ -77,8 +77,6 @@ where

/// Returns the cid codec.
pub fn codec(&self) -> U
where
U: Copy,
{
self.codec
}
Expand All @@ -93,8 +91,6 @@ where
}

fn to_string_v1(&self) -> String
where
U: Copy,
{
multibase::encode(Base::Base32Lower, self.to_bytes().as_slice())
}
Expand All @@ -104,8 +100,6 @@ where
}

fn to_bytes_v1(&self) -> Vec<u8>
where
U: Copy,
{
let mut res = Vec::with_capacity(16);

Expand All @@ -122,8 +116,6 @@ where

/// Convert CID to encoded bytes.
pub fn to_bytes(&self) -> Vec<u8>
where
U: Copy,
{
match self.version {
Version::V0 => self.to_bytes_v0(),
Expand Down Expand Up @@ -163,9 +155,9 @@ where

impl<T, U> std::str::FromStr for CidGeneric<T, U>
where
T: Into<u64> + TryFrom<u64>,
T: Into<u64> + TryFrom<u64> + Copy,
<T as TryFrom<u64>>::Error: std::fmt::Debug,
U: Into<u64> + TryFrom<u64>,
U: Into<u64> + TryFrom<u64> + Copy,
<U as TryFrom<u64>>::Error: std::fmt::Debug,
{
type Err = Error;
Expand All @@ -177,9 +169,9 @@ where

impl<T, U> TryFrom<String> for CidGeneric<T, U>
where
T: Into<u64> + TryFrom<u64>,
T: Into<u64> + TryFrom<u64> + Copy,
<T as TryFrom<u64>>::Error: std::fmt::Debug,
U: Into<u64> + TryFrom<u64>,
U: Into<u64> + TryFrom<u64> + Copy,
<U as TryFrom<u64>>::Error: std::fmt::Debug,
{
type Error = Error;
Expand All @@ -191,9 +183,9 @@ where

impl<T, U> TryFrom<&str> for CidGeneric<T, U>
where
T: Into<u64> + TryFrom<u64>,
T: Into<u64> + TryFrom<u64> + Copy,
<T as TryFrom<u64>>::Error: std::fmt::Debug,
U: Into<u64> + TryFrom<u64>,
U: Into<u64> + TryFrom<u64> + Copy,
<U as TryFrom<u64>>::Error: std::fmt::Debug,
{
type Error = Error;
Expand Down Expand Up @@ -223,9 +215,9 @@ where

impl<T, U> TryFrom<Vec<u8>> for CidGeneric<T, U>
where
T: Into<u64> + TryFrom<u64>,
T: Into<u64> + TryFrom<u64> + Copy,
<T as TryFrom<u64>>::Error: std::fmt::Debug,
U: Into<u64> + TryFrom<u64>,
U: Into<u64> + TryFrom<u64> + Copy,
<U as TryFrom<u64>>::Error: std::fmt::Debug,
{
type Error = Error;
Expand All @@ -237,9 +229,9 @@ where

impl<T, U> TryFrom<&[u8]> for CidGeneric<T, U>
where
T: Into<u64> + TryFrom<u64>,
T: Into<u64> + TryFrom<u64> + Copy,
<T as TryFrom<u64>>::Error: std::fmt::Debug,
U: Into<u64> + TryFrom<u64>,
U: Into<u64> + TryFrom<u64> + Copy,
<U as TryFrom<u64>>::Error: std::fmt::Debug,
{
type Error = Error;
Expand Down

0 comments on commit d980eac

Please sign in to comment.