screencapturekit/cm/
block_buffer.rs

1//! `CMBlockBuffer` - Block of contiguous data
2
3use super::ffi;
4
5pub struct CMBlockBuffer(*mut std::ffi::c_void);
6
7impl PartialEq for CMBlockBuffer {
8    fn eq(&self, other: &Self) -> bool {
9        self.0 == other.0
10    }
11}
12
13impl Eq for CMBlockBuffer {}
14
15impl std::hash::Hash for CMBlockBuffer {
16    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
17        unsafe {
18            let hash_value = ffi::cm_block_buffer_hash(self.0);
19            hash_value.hash(state);
20        }
21    }
22}
23
24impl CMBlockBuffer {
25    pub fn from_raw(ptr: *mut std::ffi::c_void) -> Option<Self> {
26        if ptr.is_null() {
27            None
28        } else {
29            Some(Self(ptr))
30        }
31    }
32
33    /// # Safety
34    /// The caller must ensure the pointer is a valid `CMBlockBuffer` pointer.
35    pub unsafe fn from_ptr(ptr: *mut std::ffi::c_void) -> Self {
36        Self(ptr)
37    }
38
39    pub fn as_ptr(&self) -> *mut std::ffi::c_void {
40        self.0
41    }
42}
43
44unsafe impl Send for CMBlockBuffer {}
45unsafe impl Sync for CMBlockBuffer {}