[Rust] Borrowing Mutably for Types

Different types have different forms

R4 Cheng
Apr 12, 2023

The String Type

The Integer Type

Function:

fn add_function(num_sort_operations: &mut i32) {
*num_sort_operations += 1;
}

fn main() {
let mut num_sort_operations = 0;
add_function(&mut num_sort_operations);
}

Closure:

fn main() {
let mut num_sort_operations = 0;
(|| num_sort_operations += 1)();
}

--

--

R4 Cheng
R4 Cheng

Written by R4 Cheng

「0」が過去で「1」が未来「今」は何処にもない

No responses yet