相关疑难解决方法(0)

文字整数值在Rust中是否具有特定类型?

https://doc.rust-lang.org/book/primitive-types.html#numeric-types中,它说在

设x = 42; // x的类型为i32

这意味着默认x类型i32.

但在http://rustbyexample.com/cast/literals.html中,它说明了这一点

未填充的文字,它们的类型取决于它们的使用方式

我知道我不能使用i32索引向量,但以下代码有效:

fn main() {
    let v = vec![1, 2, 3, 4, 5];

    let j = 1;  // j has default type i32? or it has type when it is first used?
                // And what is the type of 1?

    println!("{}", v[1]); // is 1 a usize?
    println!("{}", v[j]);
}
Run Code Online (Sandbox Code Playgroud)

那么,字面积分值的类型是什么?

literals rust

3
推荐指数
1
解决办法
317
查看次数

标签 统计

literals ×1

rust ×1