malloc()/free(), . !free().free(). , , . , Drop, . , .Vec<T> , T. . , T.Drawable, draw ().Iterator :pub trait Iterator {
type Item;
fn next(&mut self) -> Option<Self::Item>;
}Iterator - Item . next() , Some(YourElementType). , None.for , IntoIterator:pub trait IntoIterator {
/// The type of the elements being iterated over.
type Item;
/// Which kind of iterator are we turning this into?
type IntoIter: Iterator<Item=Self::Item>;
fn into_iter(self) -> Self::IntoIter;
}Item , IntoIter — Iterator, .pkg-config Autotools.Cargo.toml, . c .cargo build.#include , #ifdef .#[test]
fn test_that_foo_works() {
assert!(foo() == expected_result);
}cargo test, . . Makefile, , ./// Multiples the specified number by two
///
/// ```
/// assert_eq!(multiply_by_two(5), 10);
/// ```
fn multiply_by_two(x: i32) -> i32 {
x * 2
}max (5 + 3, 4) .int short, char - — Rust . .unsafe {}) . >> — .gcc, switch() enum, ? .match(). , :impl f64 {
pub fn sin_cos(self) -> (f64, f64);
}
let angle: f64 = 42.0;
let (sin_angle, cos_angle) = angle.sin_cos();match() . .let color = "green";
match color {
"red" => println!("it's red"),
"green" => println!("it's green"),
_ => println!("it's something else"),
}my_func(true, false, false)pub struct Fubarize(pub bool);
pub struct Frobnify(pub bool);
pub struct Bazificate(pub bool);
fn my_func(Fubarize(fub): Fubarize,
Frobnify(frob): Frobnify,
Bazificate(baz): Bazificate) {
if fub {
...;
}
if frob && baz {
...;
}
}
...
my_func(Fubarize(true), Frobnify(false), Bazificate(true));#[derive(Debug)] — Rust , . , gdb .user_data.Source: https://habr.com/ru/post/350186/
All Articles