gdk/
change_data.rs

1// Copyright 2013-2018, The Gtk-rs Project Developers.
2// See the COPYRIGHT file at the top-level directory of this distribution.
3// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
4
5use libc;
6
7#[derive(Clone, Copy, Debug, PartialEq)]
8pub enum ChangeData<'a> {
9    UChars(&'a [u8]),
10    UShorts(&'a [u16]),
11    ULongs(&'a [libc::c_ulong]),
12    UChar(u8),
13    UShort(u16),
14    ULong(libc::c_ulong),
15}
16
17#[doc(hidden)]
18impl<'a> ChangeData<'a> {
19    pub fn to_glib(&'a self) -> *const u8 {
20        match *self {
21            ChangeData::UChars(d) => d.as_ptr() as *const _,
22            ChangeData::UShorts(d) => d.as_ptr() as *const _,
23            ChangeData::ULongs(d) => d.as_ptr() as *const _,
24            ChangeData::UChar(d) => &d as *const _ as *const _,
25            ChangeData::UShort(d) => &d as *const _ as *const _,
26            ChangeData::ULong(d) => &d as *const _ as *const _,
27        }
28    }
29
30    pub fn len(&'a self) -> usize {
31        match *self {
32            ChangeData::UChars(d) => d.len(),
33            ChangeData::UShorts(d) => d.len(),
34            ChangeData::ULongs(d) => d.len(),
35            ChangeData::UChar(_) | ChangeData::UShort(_) | ChangeData::ULong(_) => 1,
36        }
37    }
38}