Skip to content
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

feat: add remove entry from map #49

Merged
merged 2 commits into from
Jul 8, 2024
Merged

Conversation

Aursen
Copy link
Contributor

@Aursen Aursen commented Jul 3, 2024

No description provided.

@uint
Copy link
Collaborator

uint commented Jul 4, 2024

Hi!

Adding remove is a welcome addition, but it'd have to be implemented on the ItemAccess type instead.

https://docs.rs/storey/latest/storey/containers/struct.ItemAccess.html

Map/MapAccess itself doesn't always "hold a value" under a given key - it might just have another nested Map. The remove operation is a little confusing then:

let map = Map::<String, Map<String, Item<u32>>>::new(0);

map.access(&mut storage).entry_mut("foo").entry_mut("bar").set(&42).unwrap();

map.access(&mut storage).entry_remove("foo"); // what are we removing? there's nothing under the "foo" key in the storage backend

@uint uint self-requested a review July 4, 2024 09:33
Copy link
Collaborator

@uint uint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment

@Aursen Aursen requested a review from uint July 8, 2024 08:39
Copy link
Collaborator

@uint uint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

///
/// let mut storage = TestStorage::new();
/// let item = Item::<u64, TestEncoding>::new(0);
///
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
///
///
/// item.access(&mut storage).set(&42).unwrap();

Not a must, but this probably makes a better doc test here.

@uint uint merged commit 5e69f94 into CosmWasm:main Jul 8, 2024
2 checks passed
uint added a commit that referenced this pull request Jul 10, 2024
@github-actions github-actions bot mentioned this pull request Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants