Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added usage of Enum in basics-storing values page #119

Merged
merged 4 commits into from
Jan 18, 2023
Merged
Changes from all commits
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
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