use scrap::Capturer; pub struct Screen { capturer: Option, init_error: Option, pub width: usize, pub height: usize, } impl Screen { pub fn new(capturer: Capturer, width: usize, height: usize) -> Self { Self { capturer: Some(capturer), init_error: None, width, height, } } pub fn new_failed(init_error: anyhow::Error, width: usize, height: usize) -> Self { Self { capturer: None, init_error: Some(init_error), width, height, } } pub fn take(&mut self) -> anyhow::Result> { match self.capturer.as_mut() { Some(capturer) => { let buffer = capturer .frame() .map_err(|error| anyhow::anyhow!("failed to frame of display. {}", error))?; anyhow::Ok(buffer.to_vec()) } None => anyhow::bail!("Do not initialized"), } } } unsafe impl Send for Screen {}