From 99a5ea2a7e1b45da8631cfd9fd8cc652acd7a5e3 Mon Sep 17 00:00:00 2001 From: kirti purohit Date: Mon, 19 Dec 2022 10:00:05 +0530 Subject: [PATCH 1/4] add example of string, hash and Enum --- docs/basics/storing-values.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docs/basics/storing-values.md b/docs/basics/storing-values.md index daa137526a..8de4b09162 100644 --- a/docs/basics/storing-values.md +++ b/docs/basics/storing-values.md @@ -48,6 +48,41 @@ 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, +} +``` + +## 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. Snapshots are taken currently on per-block basis, but this logic could be later evolve + /// to take snapshots of on arbitrary length (in blocks). + EndingPeriod(BlockNumber), + /// Candle was blown. + } +``` ## Initializing Storage in Constructors From 0fa60dbe36f5b8ecf264d5be26f396486b8c9763 Mon Sep 17 00:00:00 2001 From: kirti purohit Date: Mon, 19 Dec 2022 10:02:22 +0530 Subject: [PATCH 2/4] add example of string, hash and Enum --- docs/basics/storing-values.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/docs/basics/storing-values.md b/docs/basics/storing-values.md index 8de4b09162..5713262a4b 100644 --- a/docs/basics/storing-values.md +++ b/docs/basics/storing-values.md @@ -77,13 +77,10 @@ pub enum Status { /// 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. Snapshots are taken currently on per-block basis, but this logic could be later evolve - /// to take snapshots of on arbitrary length (in blocks). - EndingPeriod(BlockNumber), - /// Candle was blown. + /// bids. } ``` - +The values of enum should be referenced as `Status::OpeningPeriod` ## Initializing Storage in Constructors Constructors are how values get initialized. From 98168f8529af0dc8122e07079dbc2f5c3ce856c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Wed, 18 Jan 2023 12:01:00 +0100 Subject: [PATCH 3/4] Update docs/basics/storing-values.md --- docs/basics/storing-values.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/basics/storing-values.md b/docs/basics/storing-values.md index 5713262a4b..8c6adad2ad 100644 --- a/docs/basics/storing-values.md +++ b/docs/basics/storing-values.md @@ -53,16 +53,16 @@ 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, + 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, } ``` From 35c43e72f4ce33794d802c5da700a087503878c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Wed, 18 Jan 2023 12:01:49 +0100 Subject: [PATCH 4/4] Update docs/basics/storing-values.md --- docs/basics/storing-values.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/basics/storing-values.md b/docs/basics/storing-values.md index 8c6adad2ad..a8b55b8c50 100644 --- a/docs/basics/storing-values.md +++ b/docs/basics/storing-values.md @@ -72,13 +72,13 @@ 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. - } + /// 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