[][src]Function tao_of_rust::ch06::functions::function_shadow

pub fn function_shadow()

函数:函数定义

Base usage: 函数屏蔽

fn f() { print!("1"); }
fn main() {
    f(); // 2
    {
        f(); // 3
        fn f() { print!("3"); } // 只在当前块作用域有效
    }
    f(); // 2
    fn f() { print!("2"); }
}Run

Base usage: Rust 2018 利用原始标识(Raw identifiers)来将保留字作为函数名

fn r#match(needle: &str, haystack: &str) -> bool {
    haystack.contains(needle)
}
 
fn main() {
    assert!(r#match("foo", "foobar"));
}Run