Skip to content

Commit d6d45c0

Browse files
更新文档, 提升版本号并发布
1 parent 6ce25af commit d6d45c0

File tree

5 files changed

+121
-9
lines changed

5 files changed

+121
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ keywords = [
1212
]
1313
repository = "https://github.com/Natural-selection1/better-comprehension-in-rust"
1414
readme = "README.md"
15-
version = "3.0.2"
15+
version = "3.0.3"
1616
edition = "2024"
1717
exclude = [
1818
"src/main.rs",

README-CN.md

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# better_comprehension
1+
# 更好的推导式
22

33
在rust中的集合推导式和迭代器推导式, 提供更好的Rust使用体验
44

@@ -17,23 +17,50 @@
1717
(不计划支持, 因为本库已经提供了所有rust标准库中的集合类型)
1818

1919
* 暂未支持while loop
20-
21-
20+
(不计划支持, [使用let表达式](#let-表达式)就已经足够强大了)
2221

2322

2423
# 说明
25-
26-
语法源自 [python推导式](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions)
24+
语法源自 [python推导式](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions), 但提供了更为强大的功能, 更接近 rust 的使用习惯
2725

2826
本库为Rust标准库中的所有集合类型提供推导式宏
2927
( Vec 和 std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque})
3028

3129
以及基于引用的迭代器推导式宏
3230

31+
## 语法总览
32+
值容器
3333

34+
left_mapping < if `conditions` else `right_mapping` >?
35+
< for `pattern` in `iterable` < if `conditions` >?
36+
< let `expression` >* >+
3437

35-
# 集合推导式
3638

39+
[键值对容器](#键值对容器类型)
40+
41+
支持三种键值对表示方式, 分别是 `=>` `,` `:`
42+
以下使用 `=>` 作为例子
43+
44+
`left_key`=>`left_value` < if `conditions` else `right_key`=>`right_value`>?
45+
< for `pattern` in `iterable` < if `conditions` >?
46+
< let `expression` >* >+
47+
48+
`?` 表示可选
49+
`+` 表示至少出现一次
50+
`*` 表示出现0次或多次
51+
换行不是必须的, 只是为了可读性
52+
53+
`left/right_mapping/key/value` 是产生一个值的表达式, 可以是[简单表达式](#简单示例), 也可以是[块表达式](#使用块在返回前执行代码)
54+
55+
`if conditions` 是一个产生bool的表达式
56+
57+
`for pattern in iterable` 其中 `pattern`[模式](#使用模式匹配), `iterable` 是可迭代对象
58+
59+
`let expression` 是一个let表达式, 可以[绑定变量](#使用let表达式绑定变量) 或者[执行任意代码](#使用-let-_--或-let---执行任意代码)
60+
61+
62+
63+
# 集合推导式
3764
你可以完全将集合推导式宏视为 `for` 循环的语法糖
3865
(事实上, 这些宏就是使用 `for` 循环实现的)
3966
所以你可以看到很多很熟悉的语法

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,51 @@ Partially covered libraries:
2222

2323
* Does not support while loop
2424

25+
(No plans to support this, [using let expression](#let-expression) is already powerful enough)
2526

26-
# Collection Comprehensions
27+
# Overview
28+
The syntax is derived from [python comprehensions](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions), but provides more powerful features, closer to the usage of Rust
29+
30+
This library provides comprehension macros for all collection types in the Rust standard library
31+
32+
( Vec and std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque})
33+
34+
And provides iterator comprehension macros based on references
35+
36+
## Syntax
37+
Value container
38+
```ignore
39+
left_mapping <if conditions else right_mapping>?
40+
<for pattern in iterable <if conditions>?
41+
<let expression>*>+
42+
```
43+
44+
[Key-value container](#key-value-collection-types)
45+
46+
Supports three key-value pair representations, which are `=>` `,` `:`
47+
48+
The following uses `=>` as an example
2749

50+
```ignore
51+
left_key=>left_value <if conditions else right_key=>right_value>?
52+
<for pattern in iterable <if conditions>?
53+
<let expression>*>+
54+
```
55+
56+
*`?` means optional*
57+
58+
*`+` means at least once*
59+
60+
*`*` means 0 times or more times*
61+
62+
*It is not required to break lines, it is just for readability*
63+
64+
* `left/right_mapping/key/value` is an expression that produces a value, which can be a [simple expression](#simple-example), or a [block expression](#execute-code-in-block-before-returning)
65+
* `if conditions` is an expression that produces a bool
66+
* `for pattern in iterable` where `pattern` is a [pattern](#use-pattern-matching), and `iterable` is an iterable object
67+
* `let expression` is a let expression, which can [bind variables](#use-let-expression-to-bind-variables) or [execute arbitrary code](#use-let-_--or-let---to-execute-code)
68+
69+
# Collection Comprehensions
2870
You can completely treat collection comprehension macros as sugar for `for loop`
2971
(In fact, these macros are implemented using `for loop`)
3072
So you'll see many familiar syntaxes

src/lib.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,49 @@ Partially covered libraries:
2323
2424
* Does not support while loop
2525
26+
(No plans to support this, [using let expression](#let-expression) is already powerful enough)
27+
28+
# Overview
29+
The syntax is derived from [python comprehensions](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions), but provides more powerful features, closer to the usage of Rust
30+
31+
This library provides comprehension macros for all collection types in the Rust standard library
32+
33+
( Vec and std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque})
34+
35+
And provides iterator comprehension macros based on references
36+
37+
## Syntax
38+
Value container
39+
```ignore
40+
left_mapping <if conditions else right_mapping>?
41+
<for pattern in iterable <if conditions>?
42+
<let expression>*>+
43+
```
44+
45+
[Key-value container](#key-value-collection-types)
46+
47+
Supports three key-value pair representations, which are `=>` `,` `:`
48+
49+
The following uses `=>` as an example
50+
51+
```ignore
52+
left_key=>left_value <if conditions else right_key=>right_value>?
53+
<for pattern in iterable <if conditions>?
54+
<let expression>*>+
55+
```
56+
57+
*`?` means optional*
58+
59+
*`+` means at least once*
60+
61+
*`*` means 0 times or more times*
62+
63+
*It is not required to break lines, it is just for readability*
64+
65+
* `left/right_mapping/key/value` is an expression that produces a value, which can be a [simple expression](#simple-example), or a [block expression](#execute-code-in-block-before-returning)
66+
* `if conditions` is an expression that produces a bool
67+
* `for pattern in iterable` where `pattern` is a [pattern](#use-pattern-matching), and `iterable` is an iterable object
68+
* `let expression` is a let expression, which can [bind variables](#use-let-expression-to-bind-variables) or [execute arbitrary code](#use-let-_--or-let---to-execute-code)
2669
2770
# Collection Comprehensions
2871

0 commit comments

Comments
 (0)