Rust Error Handling, Generic Types, Traits and Lifetimes (9-10)

preview_player
Показать описание
Recording of meetup from Wednesday 15th December 2021

********************
Welcome from Rust and Cpp Cardiff! All levels welcome!
********************

Chapter 9: Error Handling
Chapter 10: Generic Types, Traits, and Lifetimes

Unfortunately, we had a few unexpected visitors this meetup so have had to cut out section where they disrupted the meetup, so apologies for the jumps in the video.

Agenda:
00:00:00 Chapter 9 - Error Handling
- 9.1. Unrecoverable Errors with panic!
- 9.2. Recoverable Errors with Result
- 9.3. To panic! or Not to panic!
00:23:39 Chapter 10 - Generic Types, Traits and Lifetimes
- 10.1. Generic Data Types
- 10.2. Traits: Defining Shared Behavior
- 10.3. Validating References with Lifetimes
00:57:56 Closing chat and plans for next few sessions

Main presenter(s): Richard
Рекомендации по теме
Комментарии
Автор

1:02:00 The example code still errors in exactly the same way. I found a way to do this outside of using match, no idea if it is a good answer or not...

fn get_or_insert_32(map: &mut HashMap<i32, String>) -> &String {
if map.get(&32) != None {
return &map[&32];
}
map.insert(32, String::from("Hello2"));
&map[&32]
}

pub fn demo_hashmap_borrow() {
let mut my_map =HashMap::new();
my_map.insert(22, String::from("hello"));
get_or_insert_32(&mut my_map);
let result = my_map.get(&32).unwrap();
println!("result: {}", result);
}

paulbird