Владение и звимствование #2
22
src/main.rs
22
src/main.rs
@@ -1,3 +1,23 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
println!("Base use owership");
|
||||||
|
base_use_owership();
|
||||||
|
println!();
|
||||||
|
println!("Base use borrowing");
|
||||||
|
base_use_borrowing();
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn base_use_owership() {
|
||||||
|
let city = String::from("Moscow");
|
||||||
|
let city_ref = &city;
|
||||||
|
|
||||||
|
println!("City: {}", city);
|
||||||
|
println!("City ref: {}", city_ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn base_use_borrowing() {
|
||||||
|
let mut s1 = "hello".to_string();
|
||||||
|
let s2 = &mut s1;
|
||||||
|
s2.push('!');
|
||||||
|
println!("{}", s1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user