Understanding Rust Closures aka. Anonymous Functions 🦀 💻

Trevor Sullivan
Trevor Sullivan
12.2 هزار بار بازدید - 12 ماه پیش - Like many other programming languages,
Like many other programming languages, Rust supports the concept of anonymous functions. In Rust, we call them "closures." Functions can be passed around, just like other data types. Rust closures have some unique functionality, however, that can trip you up while coding.

For example, Rust closure declarations use a different syntax than functions. Declaring input parameter data types for Rust closures is optional, not mandatory as with named functions. The Rust compiler is "smart" enough to figure out what data types to use for closure signature, based on your invocation of the closure. Using curly braces to surround the body of a Rust closure is also not required. Finally, borrowing mutable values in Rust closures requires that you declare the closure as mutable.

Closures are an interesting feature in Rust, and it's important that you understand exactly how they work!

🤯 Rust Programming Playlist 🦀 Rust Programming Tutorial 🦀

📖 Rust Closures: https://doc.rust-lang.org/book/ch13-0...

Visual Studio Code ➡️ https://code.visualstudio.com
Rust Website ➡️ https://rust-lang.org
Rustup Installer ➡️ https://rustup.rs
Rust Docs ➡️ https://doc.rust-lang.org/book

Please follow me on these other social channels!

➡️ https://trevorsullivan.net
➡️ https://github.com/pcgeek86
➡️ Twitter: pcgeek86
➡️ trevorsullivan
➡️ Facebook: trevorsoftware
➡️ https://tiktok.com/pcgeek86

All trademarks, logos and brand names are the property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names,trademarks and brands does not imply endorsement.

#opensource #software #linux #devops #programming #rusty #rustdev #dev #coding #codinglife #code #coder #ubuntu #ubuntulinux #appdev #rustlang #rust #developer
12 ماه پیش در تاریخ 1402/05/29 منتشر شده است.
12,279 بـار بازدید شده
... بیشتر