Skip to content

Commit

Permalink
Update awaqawaqawaq.md
Browse files Browse the repository at this point in the history
  • Loading branch information
awaqawaqawaq committed Sep 20, 2024
1 parent 61d7fe5 commit 7fe3728
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions awaqawaqawaq.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,41 @@ StarkNet's tokenomics .
MyStruct::my_function();

let map: LegacyMap<ContractAddress, u256> = LegacyMap::new(); // 指定 LegacyMap 的类型参数
### 2024.09.19
- match模式匹配,类似switch
- 模式绑定 Colors::Red(()) 括号内携带参数
``` rust
// match pattern with data (Actions)
fn match_action(self: @ContractState, action: Actions) -> u128 {
match action {
Actions::Forward(dist) => {
dist//将匹配到的值绑定至dist
},
Actions::Stop(_) => {
0_u128
}
}
}
```

- Option
调用Option::Some(value)创建一个Option::Some(value)的值,调用Option::None()创建一个Option::None的值
``` rust
let x: Option<u8> = Option::Some(5);
let y: Option<u8> = Option::None();

```
x yoption类型,可使用match模式匹配
``` rust
match option{
Option::Some(value) => value,
Option::None(_) => 0_u8,
}
```
- Into\TryInto 类型转换
- #[constructor] 在合约部署期间自动运行一次




<!-- Content_END -->

0 comments on commit 7fe3728

Please sign in to comment.