Compare commits
1 Commits
ввод_данны
...
владение_и
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4313addfdf |
34
src/main.rs
34
src/main.rs
@@ -1,15 +1,23 @@
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
println!("Пожалуйста, введите ваш возраст:");
|
||||
|
||||
let mut age = String::new();
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut age)
|
||||
.expect("Не удалось прочитать строку");
|
||||
|
||||
let age: u32 = age.trim().parse().expect("Пожалуйста, введите число!");
|
||||
|
||||
println!("Через год вам будет: {}", age + 1);
|
||||
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