Skip to content

Commit

Permalink
refactor doc of types
Browse files Browse the repository at this point in the history
  • Loading branch information
vita-dounai committed Mar 19, 2021
1 parent c0f64b1 commit 4f7a5b9
Show file tree
Hide file tree
Showing 5 changed files with 531 additions and 156 deletions.
7 changes: 6 additions & 1 deletion _static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@ img.feature-icon {
}

ul.method-introduction p {
margin-left: 2em;
margin-left: 4em;
font-size: smaller;
}

ul.method-introduction div.code-example div.highlight-rust {
margin-left: 3.4em;
}
2 changes: 1 addition & 1 deletion docs/contract/event.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Liquid 中使用结构体(`struct`)语法定义事件。结构体中的每
]
```

日志记录,`address`字段是合约地址;`data`字段中保存了非索引参数的[ABI 编解码](https://solidity.readthedocs.io/en/v0.7.1/abi-spec.html#formal-specification-of-the-encoding),此处因为我们只有一个非索引参数`i`,因此`data`字段中只保存了它的值 42;`topics`字段包含了两个可用于索引该事件的值,其中第一个是事件签名的哈希值,第二个则是事件中索引参数`s`的值的哈希值。对于`String`这类动态对象,Liquid 会将它们的哈希值作为事件索引,以提高检索效率并减少存储空间占用。因此若需要在应用中按照字符串检索事件,则需要在本地预先计算待检索字符串的哈希值。
日志记录,`address`字段是合约地址;`data`字段中保存了非索引参数的[ABI 编码](https://solidity.readthedocs.io/en/v0.7.1/abi-spec.html#formal-specification-of-the-encoding),此处因为我们只有一个非索引参数`i`,因此`data`字段中只保存了它的值 42;`topics`字段包含了两个可用于索引该事件的值,其中第一个是事件签名的哈希值,第二个则是事件中索引参数`s`的值的哈希值。对于`String`这类动态对象,Liquid 会将它们的哈希值作为事件索引,以提高检索效率并减少存储空间占用。因此若需要在应用中按照字符串检索事件,则需要在本地预先计算待检索字符串的哈希值。

```eval_rst
.. admonition:: 注意
Expand Down
54 changes: 14 additions & 40 deletions docs/contract/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,62 +69,30 @@ Liquid 中使用结构体语法(`struct`)对状态变量定义进行封装

</div>

`#[liquid(storage)]`属性标注的结构体中至少需要一个状态变量定义,因此不能将其定义为[unit 类型](https://doc.rust-lang.org/std/primitive.unit.html)
`#[liquid(storage)]`属性标注的结构体中至少需要一个状态变量定义,因此不能将其定义为[unit 类型](https://doc.rust-lang.org/std/primitive.unit.html);同时,由于每个状态变量均需要一个有效的名称,也不能将其定义为[元组类型](https://doc.rust-lang.org/stable/rust-by-example/primitives/tuples.html)。此外,不能为被`#[liquid(storage)]`属性标的结构体声明任何模板参数,即不能在该结构体中使用泛型,也不能为其添加任何可见性声明。下列代码了展示部分错误的使用方式

<div class="wrong-example">

```eval_rst
.. code-block:: rust
:linenos:
:emphasize-lines: 2
:emphasize-lines: 3, 7, 11, 17
// Unit is not allowed.
#[liquid(storage)]
struct HelloWorld();
```

</div>

每个状态变量均需要一个有效的名称,因此不能将`#[liquid(storage)]`属性标的结构体定义为[元组类型](https://doc.rust-lang.org/stable/rust-by-example/primitives/tuples.html)

<div class="wrong-example">

```eval_rst
.. code-block:: rust
:linenos:
:emphasize-lines: 2
// Tuple is not allowed.
#[liquid(storage)]
struct HelloWorld(u8, u32);
```

</div>

不能为`#[liquid(storage)]`属性标的结构体声明任何模板参数,即不能在该结构体中使用泛型:

<div class="wrong-example">

```eval_rst
.. code-block:: rust
:linenos:
:emphasize-lines: 2
// Generic is not allowed.
#[liquid(storage)]
struct HelloWorld<T, E> {
...
}
```

</div>

不能为`#[liquid(storage)]`属性标的结构体添加任何可见性声明:

<div class="wrong-example">

```eval_rst
.. code-block:: rust
:linenos:
:emphasize-lines: 2
// Visibility is not allowed.
#[liquid(storage)]
pub struct HelloWorld {
...
Expand All @@ -133,7 +101,7 @@ Liquid 中使用结构体语法(`struct`)对状态变量定义进行封装

</div>

但是可以在状态变量的定义之前添加一个`pub`可见性声明:
但是可以在状态变量的定义之前添加`pub`可见性声明:

```eval_rst
.. code-block:: rust
Expand All @@ -146,7 +114,7 @@ Liquid 中使用结构体语法(`struct`)对状态变量定义进行封装
}
```

`pub`可见性代表外界可以直接访问该状态变量,Liquid 会自动为此类状态变量生成一个公开的访问器。关于访问器的更多细节可参考[合约方法](./method.html#id8)一节。但是除了`pub`可见性以外,其他类型的可见性均不能使用
`pub`可见性代表外界可以直接访问该状态变量,Liquid 会自动为此类状态变量生成一个公开的访问器。关于访问器的更多细节可参考[合约方法](./method.html#id8)一节。但是除了`pub`可见性以外,其他种类的可见性声明均不能使用

## 容器

Expand Down Expand Up @@ -844,6 +812,12 @@ pub fn insert(&mut self, key: K, val: V) -> Option<V>
</p>
</ul>

```eval_rst
.. admonition:: 注意

可迭代映射容器的容量大小并不能无限增长,其上限为2 \ :sup:`32` - 14294967295,约为42亿)。
```

```eval_rst
.. admonition:: 注意

Expand Down

0 comments on commit 4f7a5b9

Please sign in to comment.