1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Take a look at the license at the top of the repository in the LICENSE file.

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ChangeData<'a> {
    UChars(&'a [u8]),
    UShorts(&'a [u16]),
    ULongs(&'a [libc::c_ulong]),
    UChar(u8),
    UShort(u16),
    ULong(libc::c_ulong),
}

#[doc(hidden)]
impl<'a> ChangeData<'a> {
    pub fn to_glib(&self) -> *const u8 {
        match *self {
            Self::UChars(d) => d.as_ptr() as *const _,
            Self::UShorts(d) => d.as_ptr() as *const _,
            Self::ULongs(d) => d.as_ptr() as *const _,
            Self::UChar(d) => &d as *const _ as *const _,
            Self::UShort(d) => &d as *const _ as *const _,
            Self::ULong(d) => &d as *const _ as *const _,
        }
    }

    pub fn len(&self) -> usize {
        match *self {
            Self::UChars(d) => d.len(),
            Self::UShorts(d) => d.len(),
            Self::ULongs(d) => d.len(),
            Self::UChar(_) | Self::UShort(_) | Self::ULong(_) => 1,
        }
    }

    pub fn is_empty(&self) -> bool {
        self.len() != 0
    }
}