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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use super::types::SBType;
use sys;
pub struct SBTypeList {
pub raw: sys::SBTypeListRef,
}
impl SBTypeList {
pub fn wrap(raw: sys::SBTypeListRef) -> SBTypeList {
SBTypeList { raw: raw }
}
#[allow(missing_docs)]
pub fn append(&self, t: &SBType) {
unsafe { sys::SBTypeListAppend(self.raw, t.raw) };
}
pub fn is_empty(&self) -> bool {
unsafe { sys::SBTypeListGetSize(self.raw) == 0 }
}
pub fn iter(&self) -> SBTypeListIter {
SBTypeListIter {
type_list: self,
idx: 0,
}
}
}
impl Drop for SBTypeList {
fn drop(&mut self) {
unsafe { sys::DisposeSBTypeList(self.raw) };
}
}
pub struct SBTypeListIter<'d> {
type_list: &'d SBTypeList,
idx: usize,
}
impl<'d> Iterator for SBTypeListIter<'d> {
type Item = SBType;
fn next(&mut self) -> Option<SBType> {
if self.idx < unsafe { sys::SBTypeListGetSize(self.type_list.raw) as usize } {
let r = SBType::wrap(unsafe {
sys::SBTypeListGetTypeAtIndex(self.type_list.raw, self.idx as u32)
});
self.idx += 1;
Some(r)
} else {
None
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
let sz = unsafe { sys::SBTypeListGetSize(self.type_list.raw) } as usize;
(sz - self.idx, Some(sz))
}
}