rust - Rust 中的 "0is"表示法是什么?

标签 rust syntax rust-obsolete

如在此存储库中所见:

https://github.com/ReactiveX/RxRust/blob/master/src/lib.rs#L110

let gen = move |:| {
    let it = range(0is, 20is);
    //             ~~~  ~~~~
    let q   = Box::new(Decoupler::new(dtx.clone()));
    let mut map1 = Box::new(Map::new(|i : isize| {i * 10}));
    let mut map2 = Box::new(Map::new(|i : isize| {i + 2}));
    let mut iter = Box::new(IterPublisher::new(it));


    map2.subscribe(q);
    map1.subscribe(map2);
    iter.subscribe(map1);
};

(用波浪线强调我的)

我想弄清楚数字后面的 是什么。本书仅简要介绍了文字后缀:

Note that all number literals except the byte literal allow a type suffix, such as 57u8, and _ as a visual separator, such as 1_000.

https://doc.rust-lang.org/book/ch03-02-data-types.html#integer-types

而且编译器 (1.53) 只能理解一组特定的后缀,所以我什至无法在我的机器上构建原始 crate:

invalid suffix `is`
help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)

这是某种古老的语法,还是我遗漏了什么?

最佳答案

在旧的 1.0 之前的时代,整数后缀有点不同。

感谢 Wayback Machine ,我们可以回顾一下过去:

There are 10 valid values for an integer suffix: \

  • The is and us suffixes give the literal type isize or usize, respectively.
  • Each of the signed and unsigned machine types u8, i8, u16, i16, u32, i32, u64 and i64 give the literal the corresponding machine type.

但在 Rust 1.0 中,第一个项目符号消失了,现在您编写 20isize 而不是 20is

关于rust - Rust 中的 "0is"表示法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68767869/

相关文章:

Python:如果集合中没有负计数器部分,则删除集合中的数字

javascript - 脱离 JavaScript 变量

使用rust "error: moving out of immutable field"

rust - 如何在 Rust 0.13.0 中获得平方根?

rust - 如何让 Rust 编译器解析从 std 导入?

rust - 宏可以简化特质暗示吗?

rust - 嵌套循环打印出奇怪的结果

swift - 为什么我需要转换这个通用返回值?

rust - 没有方法解析字符串

rust - 使用字符串访问向量元素