refactor/request: simplify MutateMDataEntries requests #78
Conversation
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'm good with these changes from an SCL standpoint. Vaults will require changes for this too.
|
The latest commit adds a new error in case of a type mismatch. This mismatch was impossible before this PR (we had two request types for seq and unseq separately, not one request for both), so I'm wondering if a slightly simplified API is worth the increased potential for errors. I'm leaning towards closing this PR. |
|
I was wrong - the type mismatch was possible before this PR, because you could provide a |
726efd1
to
bcc657f
Compare
src/mutable_data.rs
Outdated
| pub fn mutate_entries(&mut self, actions: EntryActions, requester: PublicKey) -> Result<()> { | ||
| match (self, actions) { | ||
| (Data::Seq(data), EntryActions::Seq(ref actions)) => { | ||
| data.mutate_entries(actions.clone(), requester) |
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.
actions is passed by value so I don't think the clone is necessary.
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.
If I try removing the clone I get this error:
error[E0507]: cannot move out of borrowed content
--> src/mutable_data.rs:747:37
|
747 | data.mutate_entries(*actions, requester)
| ^^^^^^^^ cannot move out of borrowed content
If I try not taking actions by reference I get this:
error[E0009]: cannot bind by-move and by-ref in the same pattern
--> src/mutable_data.rs:749:53
|
749 | (Data::Unseq(data), EntryActions::Unseq(actions)) => {
| ---- ^^^^^^^ by-move pattern here
| |
| both by-ref and by-move used
Don't see a way around these errors, so I left the code as-is and added a comment.
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.
Hm, just tried in in rust playground. Apparently it's not possible to match by reference and by move in the same pattern. A way around this could be to restructure it somehow like this:
match self {
Data::Seq(data) => if let EntryActions::Seq(actions) = actions {
return data.mutate_entries(actions, requester);
},
Data::Unseq(data) => if let EntryAction::Unseq(actions) = actions {
return data.mutate_entries(actions, requester);
}
}
Error(Err::InvalidOperation)
src/errors.rs
Outdated
| @@ -50,6 +50,8 @@ pub enum Error { | |||
| TooManyEntries, | |||
| /// Some entry actions are not valid. | |||
| InvalidEntryActions(BTreeMap<Vec<u8>, EntryError>), | |||
| /// The entry actions do not match the given data. | |||
| EntryActionsMismatch, | |||
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 we avoid introducing this variant and use just InvalidOperation instead?
a2d1636
to
24f17b5
Compare
No description provided.