learning-rust / learning-rust.github.io

Rust Programming Language Tutorials for Everyone!
https://learning-rust.github.io
MIT License
1.48k stars 165 forks source link

Update a7.functions.md #64

Closed 0xmahdirostami closed 11 months ago

dumindu commented 11 months ago

This example for type declarations for the let p1 with function pointers, not for let x

// 01. Without type declarations.
let p1 = plus_one;

// 02. With type declarations.
let p1: fn(i32) -> i32 = plus_one;
fn plus_one(a: i32) -> i32 {
    a + 1
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4a0e5a13d96ef71e49dc0dc3d812ae90