Skip to content

Commit

Permalink
Remove Clone bound for serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
sbihel committed Jul 5, 2024
1 parent e96d767 commit 6c0bd1d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions crates/claims/crates/vc/src/syntax/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub type AnyJsonCredential<S = json_syntax::Object> = AnySpecializedJsonCredenti
#[serde(
untagged,
bound(
serialize = "S: Serialize + Clone",
serialize = "S: Serialize",
deserialize = "S: Deserialize<'de> + Clone, C: RequiredContextList, T: RequiredTypeSet"
)
)]
Expand Down Expand Up @@ -75,7 +75,7 @@ impl<S, C, T> MaybeIdentified for AnySpecializedJsonCredential<S, C, T> {

impl<S, C, T> ssi_json_ld::Expandable for AnySpecializedJsonCredential<S, C, T>
where
S: Serialize + Clone,
S: Serialize,
{
type Error = JsonLdError;

Expand Down
20 changes: 14 additions & 6 deletions crates/claims/crates/vc/src/syntax/non_empty_vec.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use serde::{Deserialize, Serialize};
use std::ops::Deref;

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[serde(try_from = "Vec<T>", into = "Vec<T>")]
#[serde(bound(
serialize = "T: Serialize + Clone",
deserialize = "T: Deserialize<'de> + Clone"
))]
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
#[serde(try_from = "Vec<T>")]
pub struct NonEmptyVec<T>(Vec<T>);

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -88,3 +84,15 @@ impl<'a, T> IntoIterator for &'a mut NonEmptyVec<T> {
self.0.iter_mut()
}
}

impl<T> Serialize for NonEmptyVec<T>
where
T: Serialize,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.0.serialize(serializer)
}
}
4 changes: 2 additions & 2 deletions crates/claims/crates/vc/src/v2/syntax/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub type JsonCredential<S = NonEmptyObject> = SpecializedJsonCredential<S>;
/// [`JsonCredential`] type alias instead.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(bound(
serialize = "S: Serialize + Clone",
serialize = "S: Serialize",
deserialize = "S: Deserialize<'de> + Clone, C: RequiredContextList, T: RequiredTypeSet"
))]
pub struct SpecializedJsonCredential<S = NonEmptyObject, C = (), T = ()> {
Expand Down Expand Up @@ -218,7 +218,7 @@ impl<S, C, T> crate::v2::Credential for SpecializedJsonCredential<S, C, T> {

impl<S, C, T> ssi_json_ld::Expandable for SpecializedJsonCredential<S, C, T>
where
S: Serialize + Clone,
S: Serialize,
{
type Error = JsonLdError;

Expand Down

0 comments on commit 6c0bd1d

Please sign in to comment.