Skip to content

Commit de87771

Browse files
docs: add setup() to CircularBuffer example to show required initialization (#6046)
Co-authored-by: Ernesto García <ernestognw@gmail.com>
1 parent d7181c3 commit de87771

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

contracts/utils/structs/CircularBuffer.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,19 @@ import {Panic} from "../Panic.sol";
3434
*
3535
* // Declare a buffer storage variable
3636
* CircularBuffer.Bytes32CircularBuffer private myBuffer;
37+
*
38+
* constructor() {
39+
* myBuffer.setup(16); // Initialize the buffer with a non-zero fixed size (e.g., 16)
40+
* }
41+
*
42+
* function pushValue(bytes32 value) external {
43+
* myBuffer.push(value); // Safe to push because the buffer was initialized in the constructor
44+
* }
3745
* }
3846
* ```
3947
*
48+
* NOTE: Make sure to call {setup} on your buffer during construction/initialization
49+
*
4050
* _Available since v5.1._
4151
*/
4252
library CircularBuffer {

0 commit comments

Comments
 (0)