November 2017
Beginner
308 pages
8h 32m
English
As we saw back in Chapter 8, The Rust Application Lifetime, there are two main types of scope: global and local. A variable that has a local scope goes out of bounds as soon as it is finished with, whereas a global scope variable is cleaned up when the application terminates. A global scope variable is also given the lifetime marker, '.
Closures also have different scopes. Typically, they will only be for the lifetime if they are called in, but they can also be global.
A "normal" function (as shown previously) would be as follows:
fn call_with_three<F>(some_closure: F) -> i32 where F : Fn(i32) -> i32{some_closure(3)}
Conversely, for a lifetime scope, we would have the following:
fn call_with_three<'a, ...
Read now
Unlock full access