phil-opp / blog_os

Writing an OS in Rust
http://os.phil-opp.com
Apache License 2.0
15.85k stars 1.09k forks source link

Edition 3: Post 3: Proposal to change the contents of a certain code snippet #1316

Open a-usr opened 7 months ago

a-usr commented 7 months ago

For the Last snippet in post 3 it is mentioned that it was "required jump through some hoops to satisfy the borrow checker". However, when using a if let statement to pattern match the FrameBuffer out of the option and then getting the info and buffer like so:

fn kernel_main(boot_info: &'static mut bootloader_api::BootInfo) -> ! {
    if let Some(frame) = boot_info.framebuffer.as_mut(){
        // it is important to get the info first, or else the borrow checker will complain
        let info = frame.info();
        let buffer = frame.buffer_mut();
        init_logger(buffer, info);
    }
    loop{}
}

the borrow checker doesnt complain whatsoever. Would it be possible to update your code accordingly?