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
use crate::helpers::pool;
use crate::types::{frefid_t, schanid_t, strid_t, winid_t};

/** Implement ObjId trait to allow frefid_t to be used as object id in pool. */
impl pool::ObjId for frefid_t {
    const NULL: frefid_t = 0 as frefid_t;
    fn from_index(val: usize) -> Self {
        val.wrapping_add(1) as Self
    }
    fn into_index(self) -> usize {
        (self as usize).wrapping_sub(1)
    }
}

/** Implement ObjId trait to allow schanid_t to be used as object id in pool. */
impl pool::ObjId for schanid_t {
    const NULL: schanid_t = 0 as schanid_t;
    fn from_index(val: usize) -> Self {
        val.wrapping_add(1) as Self
    }
    fn into_index(self) -> usize {
        (self as usize).wrapping_sub(1)
    }
}

/** Implement ObjId trait to allow strid_t to be used as object id in pool. */
impl pool::ObjId for strid_t {
    const NULL: strid_t = 0 as strid_t;
    fn from_index(val: usize) -> Self {
        val.wrapping_add(1) as Self
    }
    fn into_index(self) -> usize {
        (self as usize).wrapping_sub(1)
    }
}

/** Implement ObjId trait to allow winid_t to be used as object id in pool. */
impl pool::ObjId for winid_t {
    const NULL: winid_t = 0 as winid_t;
    fn from_index(val: usize) -> Self {
        val.wrapping_add(1) as Self
    }
    fn into_index(self) -> usize {
        (self as usize).wrapping_sub(1)
    }
}