January 2018
Beginner to intermediate
454 pages
10h 8m
English
But how does it work behind the scene? Rust uses the idiom of Resource Acquisition Is Initialization(RAII) for short. With this idiom, a resource is allocated in the constructor and released in its destructor. In Rust, destructors are implemented by the Drop trait. So, to get back to mutex guards, the mutex is unlocked when the destructor of MutexGuard is called, so, as in the previous example, when the guard variable goes out of scope.
Let's get back to our infinite loop:
loop { if let Some(action) = event_loop.queue.try_pop() { // … } else if *event_loop.playing.lock().unwrap() { let mut written = false; if let Some(ref mut source) = source { let size = iter_to_buffer(source, &mut buffer); if size > 0 { playback.write(&buffer[..size]); ...Read now
Unlock full access