January 2018
Beginner to intermediate
454 pages
10h 8m
English
We'll also change some code before we continue. Since we'll want to share our Playlist widget with different parts of our code, including some event handlers, we need a way of sharing a reference that will last long enough (remember the issue we had with the lifetime). One easy way of doing so is to use a reference-counting pointer type—Rc. So, in our App structure, let's change the playlist field to use an Rc:
struct App { adjustment: Adjustment, cover: Image, playlist: Rc<Playlist>, toolbar: MusicToolbar, window: Window, }
This requires a new import at the top of the main module:
use std::rc::Rc;
Also, the creation of the playlist needs to be updated:
let playlist = Rc::new(Playlist::new());
We now wrap the
Read now
Unlock full access