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/

相关文章:

string - 多行字符串文字的语法是什么?

rust - vector 的借用引用的生命周期与其包含的借用指针之间有什么关系?

Python:从字符串访问类属性

rust - 你将如何在 Rust 中实现双向链表?

rust - "expected crate directive"使用rust 错误

rust - 如何使用Serde::yaml遍历使用rust 的Yaml?

linux - 使用 std::process::Command 时未正确传递长格式参数

rust - 无法移出共享引用后面的 ***

rust - 为 Rust CLI 工具编写手册页的惯用方式是什么?

php - PHP 中单引号和双引号字符串有什么区别?