Rust變量綁定
Rust通過靜態類型提供類型安全。變量綁定可以在聲明類型注解的時候。然而,在大多數情況下,編譯器將能夠推斷出變量的類型從上下文,嚴重降低了注解負擔。
值(如文本)可以綁定變量,使用 let 綁定。
fn main() { let an_integer = 1u32; let a_boolean = true; let unit = (); // copy `an_integer` into `copied_integer` let copied_integer = an_integer; println!("An integer: {:?}", copied_integer); println!("A boolean: {:?}", a_boolean); println!("Meet the unit value: {:?}", unit); // The compiler warns about unused variable bindings; these warnings can // be silenced by prefixing the variable name with an underscore let _unused_variable = 3u32; let noisy_unused_variable = 2u32; // FIXME ^ Prefix with an underscore to suppress the warning }