winit/platform_impl/linux/x11/util/
format.rs1use std::{fmt::Debug, mem, os::raw::*};
2
3#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
8pub enum Format {
9 Char = 8,
10 Short = 16,
11 Long = 32,
12}
13
14impl Format {
15 pub fn from_format(format: usize) -> Option<Self> {
16 match format {
17 8 => Some(Format::Char),
18 16 => Some(Format::Short),
19 32 => Some(Format::Long),
20 _ => None,
21 }
22 }
23
24 pub fn get_actual_size(&self) -> usize {
25 match self {
26 &Format::Char => mem::size_of::<c_char>(),
27 &Format::Short => mem::size_of::<c_short>(),
28 &Format::Long => mem::size_of::<c_long>(),
29 }
30 }
31}
32
33pub trait Formattable: Debug + Clone + Copy + PartialEq + PartialOrd {
34 const FORMAT: Format;
35}
36
37impl Formattable for c_schar {
39 const FORMAT: Format = Format::Char;
40}
41impl Formattable for c_uchar {
42 const FORMAT: Format = Format::Char;
43}
44impl Formattable for c_short {
45 const FORMAT: Format = Format::Short;
46}
47impl Formattable for c_ushort {
48 const FORMAT: Format = Format::Short;
49}
50impl Formattable for c_long {
51 const FORMAT: Format = Format::Long;
52}
53impl Formattable for c_ulong {
54 const FORMAT: Format = Format::Long;
55}