Rust – Concept of Data Freezing
Rust is a systems programming language. In Rust, there is a concept of freezing which states that whenever data is borrowed, the borrowed data is also frozen. This frozen data cannot be modified until the references get out of scope i.e. all the bindings go out of scope.
Suppose in the given below example, we declare a mutable integer _mut_integer. Here, we are shadowing the immutable variable _mut_integer but we see that _mut_integer is already frozen in this scope as the data is bounded by the same name.
After the curly braces, _mut_integer goes out of scope.
Example 1:
Rust
fn main() {
let mut _mut_integer = 8;
{
let _reference_to_integer = _mut_integer;
_mut_integer = 7;
println!( "{}" , _reference_to_integer);
println! ( "{}" , _mut_integer)
}
_mut_integer = 4;
println!( "{}" ,_mut_integer);
}
|
Output:
Last Updated :
08 Sep, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...