Rust examples
https://www.youtube.com/watch?v=vKE0OQeAxhI&list=PLgG7lPwNdp556iIin-9eaJLlu7HL6YFv0&index=6
https://doc.rust-lang.org/book/
https://dhghomon.github.io/easy_rust/Chapter_1.html
https://tourofrust.com/00_ru.html
Подобие, как в golang
https://gobyexample.com/
https://gobyexample.com.ru/
// На всё snake_case
fn main() { println!("hi"); }
fn main() {
let mut name = String::from("Text");
let count:i8 = 255;
let count2:u8 = 127;
println!("hi {}", name);
}
let a = 13u8;
let b = 7u32;
let c = a as u32 + b;
println!("{}", c);
const PI: f32 = 3.14159; // SCREAMING_SNAKE_CASE
let nums: [i32; 3] = [1, 2, 3];
println!("{:?}", nums);
println!("{}", nums[1]);
fn add(x: i32, y: i32) -> i32 {
return x + y;
}
Несколько значений из функций (как кортеж)
fn swap(x: i32, y: i32) -> (i32, i32) {
return (y, x);
}
fn main() {
// return a tuple of return values
let result = swap(123, 321);
println!("{} {}", result.0, result.1);
// destructure the tuple into two variables names
let (a, b) = swap(result.0, result.1);
println!("{} {}", a, b);
}
fn main() {
for x in 0..-5 {
println!("{}", x);
}
for x in 0..=5 {
println!("{}", x);
}
for x in (-5..=0).rev() {
println!("{}", x);
}
}