File tree Expand file tree Collapse file tree 3 files changed +70
-1
lines changed Expand file tree Collapse file tree 3 files changed +70
-1
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,7 @@ task :bindgen do
126
126
bindgen --use-core
127
127
--allowlist-function sysdir.*
128
128
--allowlist-type sysdir.*
129
+ --blocklist-type sysdir_search_path_enumeration_state
129
130
--allowlist-var PATH_MAX
130
131
--default-enum-style rust_non_exhaustive
131
132
--constified-enum sysdir_search_path_domain_mask_t
@@ -150,6 +151,29 @@ task :bindgen do
150
151
f . puts ''
151
152
152
153
IO . copy_stream ( bindgen_io , f )
154
+
155
+ f . puts ''
156
+ f . puts <<~NEWTYPE
157
+ /// Opaque type for holding sysdir enumeration state.
158
+ #[repr(transparent)]
159
+ #[derive(Debug)]
160
+ #[allow(missing_copy_implementations)]
161
+ pub struct sysdir_search_path_enumeration_state(::core::ffi::c_uint);
162
+
163
+ impl PartialEq<::core::ffi::c_uint> for sysdir_search_path_enumeration_state {
164
+ fn eq(&self, other: &::core::ffi::c_uint) -> bool {
165
+ self.0 == *other
166
+ }
167
+ }
168
+
169
+ impl sysdir_search_path_enumeration_state {
170
+ /// Return true if the state indicates the enumeration is finished.
171
+ #[must_use]
172
+ pub fn is_finished(&self) -> bool {
173
+ self.0 == 0
174
+ }
175
+ }
176
+ NEWTYPE
153
177
end
154
178
end
155
179
Original file line number Diff line number Diff line change @@ -143,4 +143,30 @@ mod tests {
143
143
144
144
assert_eq ! ( count, 1 , "Should iterate once and find `/Users`" ) ;
145
145
}
146
+
147
+ #[ test]
148
+ fn example_and_linkage_with_opaque_state_helpers ( ) {
149
+ let mut count = 0_usize ;
150
+ let mut path = [ 0 ; PATH_MAX as usize ] ;
151
+
152
+ let dir = sysdir_search_path_directory_t:: SYSDIR_DIRECTORY_USER ;
153
+ let domain_mask = SYSDIR_DOMAIN_MASK_LOCAL ;
154
+
155
+ unsafe {
156
+ let mut state = sysdir_start_search_path_enumeration ( dir, domain_mask) ;
157
+ loop {
158
+ let path = path. as_mut_ptr ( ) . cast :: < c_char > ( ) ;
159
+ state = sysdir_get_next_search_path_enumeration ( state, path) ;
160
+ if state. is_finished ( ) {
161
+ break ;
162
+ }
163
+ let path = CStr :: from_ptr ( path) ;
164
+ let s = path. to_str ( ) . unwrap ( ) ;
165
+ assert_eq ! ( s, "/Users" ) ;
166
+ count += 1 ;
167
+ }
168
+ }
169
+
170
+ assert_eq ! ( count, 1 , "Should iterate once and find `/Users`" ) ;
171
+ }
146
172
}
Original file line number Diff line number Diff line change @@ -48,7 +48,6 @@ pub const SYSDIR_DOMAIN_MASK_NETWORK: sysdir_search_path_domain_mask_t = 4;
48
48
pub const SYSDIR_DOMAIN_MASK_SYSTEM : sysdir_search_path_domain_mask_t = 8 ;
49
49
pub const SYSDIR_DOMAIN_MASK_ALL : sysdir_search_path_domain_mask_t = 65535 ;
50
50
pub type sysdir_search_path_domain_mask_t = :: core:: ffi:: c_uint ;
51
- pub type sysdir_search_path_enumeration_state = :: core:: ffi:: c_uint ;
52
51
extern "C" {
53
52
pub fn sysdir_start_search_path_enumeration (
54
53
dir : sysdir_search_path_directory_t ,
@@ -61,3 +60,23 @@ extern "C" {
61
60
path : * mut :: core:: ffi:: c_char ,
62
61
) -> sysdir_search_path_enumeration_state ;
63
62
}
63
+
64
+ /// Opaque type for holding sysdir enumeration state.
65
+ #[ repr( transparent) ]
66
+ #[ derive( Debug ) ]
67
+ #[ allow( missing_copy_implementations) ]
68
+ pub struct sysdir_search_path_enumeration_state ( :: core:: ffi:: c_uint ) ;
69
+
70
+ impl PartialEq < :: core:: ffi:: c_uint > for sysdir_search_path_enumeration_state {
71
+ fn eq ( & self , other : & :: core:: ffi:: c_uint ) -> bool {
72
+ self . 0 == * other
73
+ }
74
+ }
75
+
76
+ impl sysdir_search_path_enumeration_state {
77
+ /// Return true if the state indicates the enumeration is finished.
78
+ #[ must_use]
79
+ pub fn is_finished ( & self ) -> bool {
80
+ self . 0 == 0
81
+ }
82
+ }
You can’t perform that action at this time.
0 commit comments