代码拉取完成,页面将自动刷新
同步操作将从 alanding/rust-by-example 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
Rust provides access to a wide variety of primitives
. A sample includes:
i8
, i16
, i32
, i64
, i128
and isize
(pointer size)u8
, u16
, u32
, u64
, u128
and usize
(pointer
size)f32
, f64
char
Unicode scalar values like 'a'
, 'α'
and '∞'
(4 bytes each)bool
either true
or false
()
, whose only possible value is an empty tuple: ()
Despite the value of a unit type being a tuple, it is not considered a compound type because it does not contain multiple values.
[1, 2, 3]
(1, true)
Variables can always be type annotated. Numbers may additionally be
annotated via a suffix or by default. Integers default to i32
and
floats to f64
. Note that Rust can also infer types from context.
fn main() {
// Variables can be type annotated.
let logical: bool = true;
let a_float: f64 = 1.0; // Regular annotation
let an_integer = 5i32; // Suffix annotation
// Or a default will be used.
let default_float = 3.0; // `f64`
let default_integer = 7; // `i32`
// A type can also be inferred from context
let mut inferred_type = 12; // Type i64 is inferred from another line
inferred_type = 4294967296i64;
// A mutable variable's value can be changed.
let mut mutable = 12; // Mutable `i32`
mutable = 21;
// Error! The type of a variable can't be changed.
mutable = true;
// Variables can be overwritten with shadowing.
let mutable = true;
}
the std
library, mut
, inference, and shadowing
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。