Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions contracts/src/utils/structs/enumerable_set/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,46 @@
//! Smart contract for managing sets.
//!
//! [`EnumerableSet`] provides a generic implementation of sets that can store
//! various data types including [`Address`], [`B256`], [`U8`], [`U16`], [`U32`],
//! [`U64`], [`U128`], and [`U256`].
//!
//! # Usage Example
//!
//! ```rust,ignore
//! use alloy_primitives::Address;
//! use openzeppelin_stylus::utils::structs::enumerable_set::EnumerableSet;
//! use stylus_sdk::prelude::*;
//!
//! #[storage]
//! pub struct MyContract {
//! members: EnumerableSet<Address>,
//! }
//!
//! impl MyContract {
Comment on lines +23 to +28
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

//! pub fn add_member(&mut self, member: Address) -> bool {
//! self.members.add(member)
//! }
//!
//! pub fn remove_member(&mut self, member: Address) -> bool {
//! self.members.remove(member)
//! }
//!
//! pub fn is_member(&self, member: Address) -> bool {
//! self.members.contains(member)
//! }
//! }
//! ```
//!
//! # Custom Storage Types
//!
//! You can implement [`EnumerableSet`] for your own storage types by implementing
//! the [`Element`] and [`Accessor`] traits (see [`element`] module). This allows
//! you to create sets of custom data structures that integrate seamlessly with
//! Stylus storage.
//!
//! **Note**: [`stylus_sdk::storage::StorageBytes`] and [`stylus_sdk::storage::StorageString`]
//! cannot currently be implemented due to current Stylus SDK limitations, but this
//! might change in the future.

pub mod element;

Expand Down
1 change: 1 addition & 0 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
** xref:uups-proxy.adoc[UUPS Proxy]

* xref:utilities.adoc[Utilities]
** xref:enumerable-set-custom.adoc[Custom EnumerableSet Implementation]
Loading