-
Notifications
You must be signed in to change notification settings - Fork 61
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
Enforce non-empty subject for VCDM v2 #572
Conversation
There is a difference between "A verifiable credential must have a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think some function names may be problematic like into
, but most importantly the Clone
can be removed (almost?) everywhere.
|
||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] | ||
#[serde(try_from = "Vec<T>", into = "Vec<T>")] | ||
pub struct NonEmptyVec<T: Clone>(Vec<T>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want the Clone
bound here. As you can see it propagates everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but I'm not sure where to put it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need it exactly? I couldn't see it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
52ee9d9 I moved the bound to serde bounds which was necessary otherwise the derive of serde traits was failing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try to implement Serialize
by hand? This is really weird, there is no reason for serde
to require Clone
here 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementing Serialize
manually help, but it didn't for Deserialize
self.0 | ||
} | ||
|
||
pub fn into<T2>(self) -> NonEmptyVec<T2> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will clash with the Into::into
function, where the intent may be to convert a NonEmptyVec
into a Vec
. So I would suggest finding another name for this, like map
(although this is usually for functions accepting a mapping function as parameter), or cast
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Considering Vec
doesn't itself implement such functions, I've decided to remove them in favour of implementing IntoIter
so a consumer can easily do the same themselves
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add impl<'a, T> IntoIterator for &'a mut NonEmptyVec<T> {}
?
You're right, but I think simply requiring it to be present doesn't make much sense because:
But I'll defer to your judgement |
I would tend to agree? I think? It's really hard to tell. If we stick to the JSON-LD interpretation, even if the value is a single object and not an array, then JSON-LD will expand it into an array. But then if this array is empty the RDF deserialization algorithm won't generate a triple with the Just to understand what we're loosing here: I can see some situations where the app adds the credential subjects to an existing credential like this:
This pattern would not be possible if we forbid empty credential subjects at the type-system level. And also its easier to implement, just by changing
into
With that in mind, I let you choose if you want to proceed, I convinced myself that I don't have a strong opinion here. Just remove the |
I've decided to move forward with this because I think it would be too easy to make a mistake otherwise (and the API already requires a subject at initialisation time) |
6c0bd1d
to
3bfa8cf
Compare
As described in the specs https://www.w3.org/TR/vc-data-model-2.0/#credential-subject