use super::CapturerBuffer;
use crate::{Capturer, Error, Monitor, Result};
impl CapturerBuffer for Vec<u8> {
#[inline]
fn as_bytes(&self) -> &[u8] {
self
}
#[inline]
fn as_bytes_mut(&mut self) -> &mut [u8] {
self
}
}
pub type VecCapturer = Capturer<Vec<u8>>;
impl TryFrom<Monitor> for VecCapturer {
type Error = Error;
fn try_from(monitor: Monitor) -> Result<Self> {
Capturer::new(monitor, |size| Ok(vec![0u8; size]))
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{FrameInfoExt, Scanner};
use serial_test::serial;
use std::{thread, time::Duration};
#[test]
#[serial]
fn vec_capturer() {
let monitor = Scanner::new().unwrap().next().unwrap();
let mut capturer: VecCapturer = monitor.try_into().unwrap();
thread::sleep(Duration::from_millis(50));
let info = capturer.capture().unwrap();
assert!(info.desktop_updated());
assert!(!capturer.buffer.as_bytes().iter().all(|&n| n == 0));
thread::sleep(Duration::from_millis(50));
let (frame_info, pointer_shape_info) = capturer.capture_with_pointer_shape().unwrap();
if frame_info.pointer_shape_updated() {
assert!(pointer_shape_info.is_some());
assert!(!capturer.pointer_shape_buffer.iter().all(|&n| n == 0));
} else {
panic!(
"Move your mouse to change the shape of the cursor during the test to check mouse capture"
);
}
}
}