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

Implement Debug for collection types #647

Merged
merged 3 commits into from
Dec 10, 2021
Merged

Conversation

itegulov
Copy link
Contributor

Closes #564

This PR implements Debug trait in a uniform fashion for UnorderedMap, UnorderedSet, LookupMap, LookupSet, TreeMap, LegacyTreeMap and LazyOption.

Where possible I tried to provide a human-readable list of elements as if it was just a plain Rust collection, but for some of them (LookupMap and LookupSet) it is impossible to do by design, so I think the best we can do is to show the known internal stuff. Implementations for TreeMap and LegacyTreeMap were actually already present, I just had to move them outside of test scope. I made one compromise in tests: in order not to complicate the test logic too much, most of them assume that the values/pairs are going to be displayed in the order of their insertion.

Also, this is just a side thought, but while implementing the traits I noticed that we could split the implementations for UnorderedSet, UnorderedMap and others into two separate set of functions when K and V are either BorshSerialize or BorshDeserialize (the way it is done in Vector: see [1], [2]).

near-sdk/src/collections/legacy_tree_map.rs Outdated Show resolved Hide resolved
near-sdk/src/collections/legacy_tree_map.rs Outdated Show resolved Hide resolved
near-sdk/src/collections/lookup_map.rs Outdated Show resolved Hide resolved
near-sdk/src/collections/lookup_map.rs Outdated Show resolved Hide resolved
near-sdk/src/collections/lookup_set.rs Outdated Show resolved Hide resolved
near-sdk/src/collections/tree_map.rs Outdated Show resolved Hide resolved
near-sdk/src/collections/tree_map.rs Outdated Show resolved Hide resolved
near-sdk/src/collections/unordered_set.rs Outdated Show resolved Hide resolved
near-sdk/src/collections/unordered_set.rs Outdated Show resolved Hide resolved
near-sdk/src/store/lazy_option/impls.rs Outdated Show resolved Hide resolved
@itegulov
Copy link
Contributor Author

@austinabell I have addressed your comments, should be better now. PTAL whenever you can.

@itegulov itegulov merged commit b40b845 into master Dec 10, 2021
@itegulov itegulov deleted the debug-for-collections branch December 10, 2021 07:13
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.

Implement debug for collection types
2 participants