1use crate::{sys, SBType};
8
9pub struct SBTypeList {
13 pub raw: sys::SBTypeListRef,
15}
16
17impl SBTypeList {
18 pub(crate) fn wrap(raw: sys::SBTypeListRef) -> SBTypeList {
20 SBTypeList { raw }
21 }
22
23 #[allow(missing_docs)]
24 pub fn append(&self, t: &SBType) {
25 unsafe { sys::SBTypeListAppend(self.raw, t.raw) };
26 }
27
28 pub fn is_empty(&self) -> bool {
30 unsafe { sys::SBTypeListGetSize(self.raw) == 0 }
31 }
32
33 pub fn iter(&self) -> SBTypeListIter {
35 SBTypeListIter {
36 type_list: self,
37 idx: 0,
38 }
39 }
40}
41
42impl Clone for SBTypeList {
43 fn clone(&self) -> SBTypeList {
44 SBTypeList {
45 raw: unsafe { sys::CloneSBTypeList(self.raw) },
46 }
47 }
48}
49
50impl Drop for SBTypeList {
51 fn drop(&mut self) {
52 unsafe { sys::DisposeSBTypeList(self.raw) };
53 }
54}
55
56impl<'d> IntoIterator for &'d SBTypeList {
57 type IntoIter = SBTypeListIter<'d>;
58 type Item = SBType;
59 fn into_iter(self) -> Self::IntoIter {
60 self.iter()
61 }
62}
63
64unsafe impl Send for SBTypeList {}
65unsafe impl Sync for SBTypeList {}
66
67pub struct SBTypeListIter<'d> {
71 type_list: &'d SBTypeList,
72 idx: usize,
73}
74
75impl Iterator for SBTypeListIter<'_> {
76 type Item = SBType;
77
78 fn next(&mut self) -> Option<SBType> {
79 if self.idx < unsafe { sys::SBTypeListGetSize(self.type_list.raw) as usize } {
80 let r = SBType::wrap(unsafe {
81 sys::SBTypeListGetTypeAtIndex(self.type_list.raw, self.idx as u32)
82 });
83 self.idx += 1;
84 Some(r)
85 } else {
86 None
87 }
88 }
89
90 fn size_hint(&self) -> (usize, Option<usize>) {
91 let sz = unsafe { sys::SBTypeListGetSize(self.type_list.raw) } as usize;
92 (sz - self.idx, Some(sz))
93 }
94}
95
96impl ExactSizeIterator for SBTypeListIter<'_> {}