File: non-english-identifier.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (47 lines) | stat: -rw-r--r-- 1,004 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#[doc(alias = "加法")]
pub fn add(left: usize, right: usize) -> usize {
    left + right
}

pub fn 中文名称的加法API(left: usize, right: usize) -> usize {
    left + right
}

#[macro_export]
macro_rules! 中文名称的加法宏 {
    ($left:expr, $right:expr) => {
        ($left) + ($right)
    };
}

#[doc(alias = "加法")]
#[macro_export]
macro_rules! add {
    ($left:expr, $right:expr) => {
        ($left) + ($right)
    };
}

/// Add
pub trait 加法<类型> {
    type 结果;
    fn 加上(self, 被加数: 类型) -> Self::结果;
}

/// IntoIterator
pub trait 可迭代 {
    type 项;
    type 转为迭代器: Iterator<Item = Self::项>;
    fn 迭代(self) -> Self::转为迭代器;
}

pub type 可选<类型> = Option<类型>;

/// "sum"
pub fn 总计<集合, 个体>(容器: 集合) -> 可选<集合::项>
where
    集合: 可迭代<项 = 个体>,
    个体: 加法<个体, 结果 = 个体>,
{
    容器.迭代().reduce(|累计值, 当前值| 累计值.加上(当前值))
}