Skip to content

Conversation

sumitvekariya
Copy link

Description

This PR addresses issue #761 by adding comprehensive documentation for implementing custom EnumerableSet types in Stylus contracts.

Changes Made

Enhanced EnumerableSet Module Documentation

  • Added detailed module-level documentation with usage examples
  • Included EnumerableSet<Address> example showing basic usage patterns
  • Documented how to implement custom storage types via Element and Accessor traits
  • Added limitation notes about StorageBytes and StorageString

Created Comprehensive Antora Documentation

  • Added new documentation file: docs/modules/ROOT/pages/enumerable-set-custom.adoc
  • Provided step-by-step implementation guide for custom storage types
  • Included complete working examples with custom UserId and ProductId types
  • Documented all built-in supported types (Address, B256, U8, U16, U32, U64, U128, U256)
  • Added best practices, gas considerations, and testing guidance

Updated Navigation and Cross-References

  • Added new documentation to docs/modules/ROOT/nav.adoc
  • Updated docs/modules/ROOT/pages/utilities.adoc with cross-reference to new guide

Addressed Current Limitations

  • Clearly documented that StorageBytes and StorageString cannot currently be implemented due to Stylus SDK limitations
  • Noted that this might change in future SDK versions

Testing

  • ✅ Documentation builds successfully with npm run docs
  • ✅ All Rust tests pass (88 EnumerableSet property tests)
  • ✅ Code compiles without errors
  • ✅ No breaking changes to existing functionality

Related Issues

Closes #761

Notes

This implementation provides developers with clear, comprehensive guidance on:

  • Using built-in EnumerableSet types
  • Implementing custom storage types
  • Following best practices for gas optimization
  • Testing custom implementations

The documentation includes complete, working code examples that developers can copy and adapt for their own use cases.

…entation

- Add detailed module documentation with usage examples for EnumerableSet
- Create comprehensive Antora documentation guide for custom types
- Include step-by-step implementation instructions for Element and Accessor traits
- Provide complete working examples with custom UserId and ProductId types
- Document built-in support for Address, B256, and integer types
- Add best practices, gas considerations, and testing guidance
- Update navigation structure and cross-references
- Document current limitations with StorageBytes and StorageString

Addresses issue OpenZeppelin#761 by providing clear examples and docs for implementing
EnumerableSet with user-defined storage types in Stylus.
Copy link

netlify bot commented Aug 14, 2025

Deploy Preview for contracts-stylus failed. Why did it fail? →

Name Link
🔨 Latest commit efa9c0d
🔍 Latest deploy log https://app.netlify.com/projects/contracts-stylus/deploys/689d83efcad65300088d6038

Comment on lines +14 to +19
//! #[storage]
//! pub struct MyContract {
//! members: EnumerableSet<Address>,
//! }
//!
//! impl MyContract {
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
//! #[storage]
//! pub struct MyContract {
//! members: EnumerableSet<Address>,
//! }
//!
//! impl MyContract {
//! #[storage]
//! #[entrypoint]
//! pub struct MyContract {
//! members: EnumerableSet<Address>,
//! }
//!
//! #[public]
//! impl MyContract {

Let's have a complete deployable contract

@@ -49,3 +49,5 @@ Contracts for Stylus provides these libraries for enhanced data structure manage
- https://docs.rs/openzeppelin-stylus/0.3.0-rc.1/openzeppelin_stylus/utils/structs/bitmap/index.html[`BitMaps`]: Store packed booleans in storage.
- https://docs.rs/openzeppelin-stylus/0.3.0-rc.1/openzeppelin_stylus/utils/structs/checkpoints/index.html[`Checkpoints`]: Checkpoint values with built-in lookups.
- https://docs.rs/openzeppelin-stylus/0.3.0-rc.1/openzeppelin_stylus/utils/structs/enumerable_set/index.html[`EnumerableSets`]: Contract for managing sets of many primitive types.

For detailed guidance on implementing EnumerableSet with custom storage types, see xref:enumerable-set-custom.adoc[Custom EnumerableSet Implementation].
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove docs/pnpm-lock.yaml

Comment on lines +3 to +8
//! 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).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move these docs above the EnumerableSet struct.

Looking at it from dev perspective, hovering over the EnumerableSet struct I'm about to use, I'd expect it to contain docs explaining how to use it. There's a high chance devs would not know they need to hover over the module to get an example usage.

@0xNeshi
Copy link
Collaborator

0xNeshi commented Aug 15, 2025

I just noticed that another contributor was already assigned to this issue and had already created a draft PR, with just as good docs as in this PR.

We appreciate your effort on the PR, but to avoid more duplicate work for both you and them, and to avoid redundant reviews for us maintainers, we will need to close this PR. We generally assign issues to specific contributors exactly to avoid these types of situations.

For future reference, if you'd like to work on an already assigned issue, please ping us before starting any work, asking if you can take over the issue. Maybe the current assignee is inactive or their contribution is low quality, so we determine that it's better to reassign the issue to you.
Otherwise, we let you know that the issue is definitely taken, and we suggest you take a look at alternative issues that would be useful for us to have addressed.
Thanks!

@0xNeshi 0xNeshi closed this Aug 15, 2025
@sumitvekariya
Copy link
Author

I just noticed that another contributor was already assigned to this issue and had already created a draft PR, with just as good docs as in this PR.

We appreciate your effort on the PR, but to avoid more duplicate work for both you and them, and to avoid redundant reviews for us maintainers, we will need to close this PR. We generally assign issues to specific contributors exactly to avoid these types of situations.

For future reference, if you'd like to work on an already assigned issue, please ping us before starting any work, asking if you can take over the issue. Maybe the current assignee is inactive or their contribution is low quality, so we determine that it's better to reassign the issue to you. Otherwise, we let you know that the issue is definitely taken, and we suggest you take a look at alternative issues that would be useful for us to have addressed. Thanks!

Hey I totally get it, I usually take up the issues which are unassigned or assigned(long before but not actively worked upon) ones. But this one I completely missed that it had a PR drafted already, my bad. Will ask to be assigned befor start working on already assigned issues. Thanks for pointing out.

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.

[Docs]: Add Clear Examples and Docs for How to Implement Custom EnumerableSet
3 participants