Add documentation for implementing EnumerableSet#786
Conversation
…ustom storage types - Enhanced existing EnumerableSet docs with usage examples - Created comprehensive Antora documentation for custom storage types - Added note about StorageBytes/StorageString limitations - Updated navigation and cross-references Closes OpenZeppelin#761
✅ Deploy Preview for contracts-stylus ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
0xNeshi
left a comment
There was a problem hiding this comment.
Very good work 🚀
Let's polish it a bit and we can merge
| //! ``` | ||
| //! extern crate alloc; | ||
| //! | ||
| //! use alloy_primitives::{Address, U256}; | ||
| //! use stylus_sdk::prelude::*; | ||
| //! use openzeppelin_stylus::utils::structs::enumerable_set::EnumerableSet; | ||
| //! | ||
| //! #[storage] | ||
| //! struct MyContract { | ||
| //! whitelist: EnumerableSet<Address>, | ||
| //! } |
There was a problem hiding this comment.
| //! ``` | |
| //! extern crate alloc; | |
| //! | |
| //! use alloy_primitives::{Address, U256}; | |
| //! use stylus_sdk::prelude::*; | |
| //! use openzeppelin_stylus::utils::structs::enumerable_set::EnumerableSet; | |
| //! | |
| //! #[storage] | |
| //! struct MyContract { | |
| //! whitelist: EnumerableSet<Address>, | |
| //! } | |
| //! ```rust | |
| //! extern crate alloc; | |
| //! | |
| //! use alloy_primitives::{Address, U256}; | |
| //! use stylus_sdk::prelude::*; | |
| //! use openzeppelin_stylus::utils::structs::enumerable_set::EnumerableSet; | |
| //! | |
| //! #[storage] | |
| //! #[entrypoint] | |
| //! struct MyContract { | |
| //! whitelist: EnumerableSet<Address>, | |
| //! } |
There was a problem hiding this comment.
Unresolving, still missing #[entrypoint].
There was a problem hiding this comment.
Unresolving, still missing #[entrypoint].
@Peponks9 I need to remind you to please not resolve change requests which have not been addressed. This is very important, as it makes for better clarity during code reviews. Only resolve change requests once:
- The change request is addressed (implemented).
- Your local changes are pushed to remote and PR is updated.
| [[limitations]] | ||
| == Current Limitations | ||
|
|
||
| **Note:** `StorageBytes` and `StorageString` cannot currently be implemented for `EnumerableSet` due to limitations in the Stylus SDK. This limitations may change in future versions of the Stylus SDK. |
There was a problem hiding this comment.
Update the sentence to state that Bytes and String cannot currently be implemented due to SDK limitation. Link to the actual types.
There was a problem hiding this comment.
Made the changes but didn't find a link for String, just Bytes.
There was a problem hiding this comment.
There was a problem hiding this comment.
The changes haven't been made or haven't been pushed, you can resolve this conversation together with https://github.com/OpenZeppelin/rust-contracts-stylus/pull/786/files#r2281442336
| [[testing]] | ||
| == Testing Your Implementation |
There was a problem hiding this comment.
Remove this section, devs can't run OZ tests from within their projects
There was a problem hiding this comment.
Unresolving, the cargo test script is still present
There was a problem hiding this comment.
@Peponks9 another reminder not to resolve conversations that haven't been fully addressed and the changes pushed.
Add `rust` Co-authored-by: Nenad <xinef.it@gmail.com>
- Add comprehensive primitive type list with rustdoc links - Move detailed docs from module level to struct level - Update custom implementation guide with step-by-step breakdown - Fix documentation structure and formatting issues - Update limitations section with proper type links
- Add comprehensive primitive type list with rustdoc links - Move detailed docs from module level to struct level - Update custom implementation guide with step-by-step breakdown - Fix documentation structure and formatting issues - Update limitations section with proper type links
|
Hey @0xNeshi, changes made :) |
| /// Sets have the following properties: | ||
| /// | ||
| /// * Elements are added, removed, and checked for existence in constant time | ||
| /// (O(1)). | ||
| /// * Elements are enumerated in O(n). No guarantees are made on the ordering. | ||
| /// * Set can be cleared (all elements removed) in O(n). | ||
| /// | ||
| /// ## Usage |
There was a problem hiding this comment.
| /// Sets have the following properties: | |
| /// | |
| /// * Elements are added, removed, and checked for existence in constant time | |
| /// (O(1)). | |
| /// * Elements are enumerated in O(n). No guarantees are made on the ordering. | |
| /// * Set can be cleared (all elements removed) in O(n). | |
| /// | |
| /// ## Usage | |
| /// Storage type for managing [sets] of primitive types. | |
| /// | |
| /// Sets have the following properties: | |
| /// | |
| /// * Elements are added, removed, and checked for existence in constant time | |
| /// (O(1)). | |
| /// * Elements are enumerated in O(n). No guarantees are made on the ordering. | |
| /// * Set can be cleared (all elements removed) in O(n). | |
| /// | |
| /// [sets]: https://en.wikipedia.org/wiki/Set_(abstract_data_type) | |
| /// | |
| /// ## Usage |
| use stylus_sdk::prelude::TopLevelStorage; | ||
| use alloy_primitives::private::proptest::{prop_assert, prop_assert_eq, proptest}; | ||
|
|
||
|
|
There was a problem hiding this comment.
I don't seem to find this one, on lines provided it is not after use alloy_primitives::private::proptest::{prop_assert, prop_assert_eq, proptest}; anymore.
There was a problem hiding this comment.
Maybe you didn't push local changes?
| @@ -2,13 +2,6 @@ | |||
|
|
|||
There was a problem hiding this comment.
Change the mod-level doc to:
//! Storage type for managing [sets] of primitive types.
//!
//! [sets]: https://en.wikipedia.org/wiki/Set_(abstract_data_type)
| //! ``` | ||
| //! extern crate alloc; | ||
| //! | ||
| //! use alloy_primitives::{Address, U256}; | ||
| //! use stylus_sdk::prelude::*; | ||
| //! use openzeppelin_stylus::utils::structs::enumerable_set::EnumerableSet; | ||
| //! | ||
| //! #[storage] | ||
| //! struct MyContract { | ||
| //! whitelist: EnumerableSet<Address>, | ||
| //! } |
There was a problem hiding this comment.
Unresolving, still missing #[entrypoint].
| //! You can implement `EnumerableSet` for your own storage types by implementing | ||
| //! the `Element` and `Accessor` traits. See `element.rs` for trait definitions | ||
| //! and the documentation for comprehensive examples. |
There was a problem hiding this comment.
Unresolving, as types for not converted into links.
| [[limitations]] | ||
| == Current Limitations | ||
|
|
||
| **Note:** https://docs.rs/alloy-primitives/latest/alloy_primitives/struct.Bytes.html[`Bytes`] and `String` cannot currently be implemented for `EnumerableSet` due to limitations in the Stylus SDK. These limitations may change in future versions of the Stylus SDK. |
There was a problem hiding this comment.
| **Note:** https://docs.rs/alloy-primitives/latest/alloy_primitives/struct.Bytes.html[`Bytes`] and `String` cannot currently be implemented for `EnumerableSet` due to limitations in the Stylus SDK. These limitations may change in future versions of the Stylus SDK. | |
| https://docs.rs/alloy-primitives/latest/alloy_primitives/struct.Bytes.html[`Bytes`] and `String` cannot currently be implemented for `EnumerableSet` due to limitations in the Stylus SDK. These limitations may change in future versions of the Stylus SDK. |
nit: redundant, already in a separate section.
| [[limitations]] | ||
| == Current Limitations | ||
|
|
||
| **Note:** https://docs.rs/alloy-primitives/latest/alloy_primitives/struct.Bytes.html[`Bytes`] and `String` cannot currently be implemented for `EnumerableSet` due to limitations in the Stylus SDK. These limitations may change in future versions of the Stylus SDK. |
There was a problem hiding this comment.
| **Note:** https://docs.rs/alloy-primitives/latest/alloy_primitives/struct.Bytes.html[`Bytes`] and `String` cannot currently be implemented for `EnumerableSet` due to limitations in the Stylus SDK. These limitations may change in future versions of the Stylus SDK. | |
| **Note:** https://docs.rs/alloy-primitives/latest/alloy_primitives/struct.Bytes.html[`Bytes`] and https://doc.rust-lang.org/stable/alloc/string/struct.String.html[`String`] cannot currently be implemented for `EnumerableSet` due to limitations in the Stylus SDK. These limitations may change in future versions of the Stylus SDK. |
| [[testing]] | ||
| == Testing Your Implementation |
There was a problem hiding this comment.
Unresolving, the cargo test script is still present
| #[storage] | ||
| struct AccessControl { | ||
| role_members: StorageMap<B256, EnumerableSet<Address>>, | ||
| } | ||
|
|
||
| impl AccessControl { | ||
| fn grant_role(&mut self, role: B256, account: Address) { | ||
| self.role_members.get(role).add(account); | ||
| } | ||
|
|
||
| fn revoke_role(&mut self, role: B256, account: Address) { | ||
| self.role_members.get(role).remove(account); | ||
| } | ||
|
|
||
| fn get_role_members(&self, role: B256) -> Vec<Address> { | ||
| self.role_members.get(role).values() | ||
| } | ||
| } |
There was a problem hiding this comment.
Provide a full working contract example, including imports. Devs should be able to copy/paste this example and have it deployable out of the box.
| [source,rust] | ||
| ---- | ||
| #[storage] | ||
| struct Whitelist { |
There was a problem hiding this comment.
Same for this, make it fully working example
|
Also, fix the failing doc CI. The other CI jobs seem to be failing due to some issue with |
|
@0xNeshi yes, still haven’t pushed changes and some errors still to be addressed. But didn’t some progress today ñ. |
|
Hey @Peponks9 , just checking in to see if you need any help addressing the issues |
# Conflicts: # contracts/src/utils/structs/enumerable_set/mod.rs # docs/modules/ROOT/pages/utilities.adoc
Description
This PR addresses issue #761 by adding the documentation for implementing
EnumerableSetwith user-defined storage types in Stylus.Changes Made
Added Examples to Existing EnumerableSet Documentation
EnumerableSet<Address>incontracts/src/utils/structs/enumerable_set/mod.rsElementandAccessortraitsCreated Antora Documentation
docs/modules/ROOT/pages/enumerable-set-custom.adocUserstructUpdated Navigation and References
docs/modules/ROOT/nav.adocdocs/modules/ROOT/pages/utilities.adocwith cross-referenceAddressed Limitations
StorageBytesandStorageStringcannot currently be implemented due to Stylus SDK limitationsTesting
npm run docsCargo testsuccessfully runRelated Issue
Closes #761
@0xNeshi