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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use sys;
use get_api;
use std::cmp::Ordering;
use std::mem::transmute;
use std::cmp::{Eq, PartialEq};
#[derive(Copy, Clone, Debug)]
pub struct Rid(pub(crate) sys::godot_rid);
impl Rid {
pub fn new() -> Self {
Rid::default()
}
pub fn get_id(&self) -> i32 {
unsafe { (get_api().godot_rid_get_id)(&self.0) }
}
pub fn operator_less(&self, b: &Rid) -> bool {
unsafe { (get_api().godot_rid_operator_less)(&self.0, &b.0) }
}
pub fn is_valid(&self) -> bool {
self.to_u64() != 0
}
fn to_u64(&self) -> u64 {
unsafe { transmute(self.0) }
}
}
impl_basic_traits!{
for Rid as godot_rid {
Eq => godot_rid_operator_equal;
Default => godot_rid_new;
}
}
impl PartialOrd for Rid {
fn partial_cmp(&self, other: &Rid) -> Option<Ordering> {
unsafe {
let native = (get_api().godot_rid_operator_less)(&self.0, &other.0);
if native {
Some(Ordering::Less)
} else {
Some(Ordering::Greater)
}
}
}
}