Skip to main content

gdk/
change_data.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq)]
4pub enum ChangeData<'a> {
5    UChars(&'a [u8]),
6    UShorts(&'a [u16]),
7    ULongs(&'a [libc::c_ulong]),
8    UChar(u8),
9    UShort(u16),
10    ULong(libc::c_ulong),
11}
12
13#[doc(hidden)]
14impl<'a> ChangeData<'a> {
15    pub fn to_glib(&self) -> *const u8 {
16        match *self {
17            Self::UChars(d) => d.as_ptr() as *const _,
18            Self::UShorts(d) => d.as_ptr() as *const _,
19            Self::ULongs(d) => d.as_ptr() as *const _,
20            Self::UChar(d) => &d as *const _ as *const _,
21            Self::UShort(d) => &d as *const _ as *const _,
22            Self::ULong(d) => &d as *const _ as *const _,
23        }
24    }
25
26    pub fn len(&self) -> usize {
27        match *self {
28            Self::UChars(d) => d.len(),
29            Self::UShorts(d) => d.len(),
30            Self::ULongs(d) => d.len(),
31            Self::UChar(_) | Self::UShort(_) | Self::ULong(_) => 1,
32        }
33    }
34
35    pub fn is_empty(&self) -> bool {
36        self.len() != 0
37    }
38}