Add Rust type unit::Kind

This commit is contained in:
Alex Kotov 2022-09-09 00:05:17 +04:00
parent 1bf97dab72
commit 23c415dcde
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
3 changed files with 35 additions and 5 deletions

View File

@ -3,5 +3,6 @@ mod constraints;
pub mod geom; pub mod geom;
pub mod settings; pub mod settings;
pub mod unit;
pub use settings::Settings; pub use settings::Settings;

View File

@ -9,11 +9,11 @@
unit = NULL; \ unit = NULL; \
} }
typedef enum { typedef unsigned char UnitKind;
UNIT_GLOBAL = 0,
UNIT_MONITOR = 1, #define UNIT_GLOBAL 0
UNIT_TAG = 2, #define UNIT_MONITOR 1
} UnitKind; #define UNIT_TAG 2
typedef struct Unit *Unit; typedef struct Unit *Unit;

29
src/unit.rs Normal file
View File

@ -0,0 +1,29 @@
use std::os::raw::*;
#[derive(Clone, Copy, Debug)]
pub enum Kind {
Global,
Monitor,
Tag,
}
impl Into<c_uchar> for Kind {
fn into(self) -> c_uchar {
match self {
Self::Global => 0,
Self::Monitor => 1,
Self::Tag => 2,
}
}
}
impl From<c_uchar> for Kind {
fn from(value: c_uchar) -> Self {
match value {
0 => Self::Global,
1 => Self::Monitor,
2 => Self::Tag,
_ => panic!("invalid value for type Kind"),
}
}
}