Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

refactor/request: simplify MutateMDataEntries requests #78

Merged
merged 3 commits into from Jul 31, 2019

Conversation

mrcnski
Copy link
Contributor

@mrcnski mrcnski commented Jul 22, 2019

No description provided.

@mrcnski mrcnski requested a review from ustulation as a code owner July 22, 2019 11:35
Copy link
Contributor

@lionel-faber lionel-faber left a 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.

@mrcnski
Copy link
Contributor Author

mrcnski commented Jul 23, 2019

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.

@mrcnski mrcnski closed this Jul 23, 2019
@mrcnski
Copy link
Contributor Author

mrcnski commented Jul 24, 2019

I was wrong - the type mismatch was possible before this PR, because you could provide a Seq address to MutateUnseqMDataEntries, and vice versa. This change is just making a different type mismatch possible (between the provided address and new MDataEntries type) while simplifying the overall API. Reopening.

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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,
Copy link
Contributor

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?

@mrcnski mrcnski force-pushed the mutate-mdata-entries branch 2 times, most recently from a2d1636 to 24f17b5 Compare July 31, 2019 12:19
@nbaksalyar nbaksalyar merged commit 4f424f6 into maidsafe:master Jul 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants