Skip to content

Commit

Permalink
Added usage of Enum in basics-storing values page (#119)
Browse files Browse the repository at this point in the history
* add example of string, hash and Enum

* add example of string, hash and Enum

* Update docs/basics/storing-values.md

* Update docs/basics/storing-values.md

Co-authored-by: Michael Müller <[email protected]>
  • Loading branch information
Irene-123 and cmichi authored Jan 18, 2023
1 parent 94cdc3f commit 1f5e899
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docs/basics/storing-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,39 @@ mod MyContract {
/* --snip-- */
}
```
Here is an example of a structure storing `String` and `Hash` values.

```rust
pub struct Auction {
/// Branded name of the auction event.
name: String,
/// Some hash identifying the auction subject.
subject: Hash,
/// Auction status.
status: Status, // Enum: Usage shown in next section
/// Candle auction can have no winner.
/// If auction is finalized, that means that the winner is determined.
finalized: bool,
/// vector
vector: Vec<u8>,
}
```

## Use of enum

Enum can be used as a datatype in `struct` as depicted above in `struct Auction`

```rust
pub enum Status {
/// An auction has not started yet.
NotStarted,
/// We are in the starting period of the auction, collecting initial bids.
OpeningPeriod,
/// We are in the ending period of the auction, where we are taking snapshots
/// of the winning bids.
}
```
The values of enum should be referenced as `Status::OpeningPeriod`
## Initializing Storage in Constructors

Constructors are how values get initialized.
Expand Down

0 comments on commit 1f5e899

Please sign in to comment.