Ownership
fn main() {
let nums = vec![2, 4, 6];
let nums2 = nums;
println!("{:?}", nums2);
}
Immutable Borrow
fn main() {
let nums = vec![2, 4, 6];
print_nums(nums);
println!("{:?}", nums);
}
fn print_nums(nums: Vec<i32>) {
for num in nums.iter() {
println!("{}", num)
}
}
Multiple immutable borrow
fn main() {
let nums = vec![2, 4, 6];
let nums2 = &nums;
let nums3 = &nums;
let nums4 = &nums;
println!("{:?} {:?} {:?}", nums2, nums3, nums4);
}
Mutable borrow
fn main() {
let nums = vec![2, 4, 6];
extend_nums(nums);
println!("{:?}", nums);
}
fn extend_nums(mut nums: Vec<i32>) {
nums.push(8);
}
- Classic struct -
Color - Create object and access values
- Debug print
- Mutability of values
- Update for Tuple Struct
- Unit Struct
- Struct of a package with strings and weight
- Impl of ownership
- Impl of reference
- How to call a reference?
- Impl of add weight
- How to call a mut reference?
- Example of
Message-Echo,Move,ChangeColor,Quit - If else
enumand PartialEq
impl PartialEq for Message {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Message::Quit, Message::Quit) => true,
(Message::Echo, Message::Echo) => true,
(Message::Move, Message::Move) => true,
(Message::ChangeColor, Message::ChangeColor) => true,
_ => false,
}
}
}
- Enum with values
- Print - Debug
- Impl for call
- Match
String::fromforfoobar- How to get a slice from a string
- Trim string
- Replace
barwithbaz - Replacement needs a new String. Why?
- String concatenation
push_strformat!
- Crate root
- mod
fooand how to call - mod
barand how to callfoofrom there - export and import
- Separate into files
- Separate into folders