File tree Expand file tree Collapse file tree 5 files changed +46
-21
lines changed Expand file tree Collapse file tree 5 files changed +46
-21
lines changed Original file line number Diff line number Diff line change @@ -249,9 +249,9 @@ status = "generate"
249
249
ignore = true
250
250
[[object .function ]]
251
251
name = " content_type_guess"
252
- [[ object . function . parameter ]]
253
- name = " filename "
254
- string_type = " filename "
252
+ # implemented manually until gir generates nullable array parameters
253
+ # https://github.com/gtk-rs/gir/issues/1133
254
+ manual = true
255
255
256
256
[[object ]]
257
257
name = " Gio.ActionGroup"
Original file line number Diff line number Diff line change @@ -178,24 +178,6 @@ pub fn content_type_get_symbolic_icon(type_: &str) -> Icon {
178
178
}
179
179
}
180
180
181
- #[ doc( alias = "g_content_type_guess" ) ]
182
- pub fn content_type_guess (
183
- filename : Option < impl AsRef < std:: path:: Path > > ,
184
- data : & [ u8 ] ,
185
- ) -> ( glib:: GString , bool ) {
186
- let data_size = data. len ( ) as _ ;
187
- unsafe {
188
- let mut result_uncertain = std:: mem:: MaybeUninit :: uninit ( ) ;
189
- let ret = from_glib_full ( ffi:: g_content_type_guess (
190
- filename. as_ref ( ) . map ( |p| p. as_ref ( ) ) . to_glib_none ( ) . 0 ,
191
- data. to_glib_none ( ) . 0 ,
192
- data_size,
193
- result_uncertain. as_mut_ptr ( ) ,
194
- ) ) ;
195
- ( ret, from_glib ( result_uncertain. assume_init ( ) ) )
196
- }
197
- }
198
-
199
181
#[ doc( alias = "g_content_type_guess_for_tree" ) ]
200
182
pub fn content_type_guess_for_tree ( root : & impl IsA < File > ) -> Vec < glib:: GString > {
201
183
unsafe {
Original file line number Diff line number Diff line change
1
+ // Take a look at the license at the top of the repository in the LICENSE file.
2
+
3
+ use std:: ptr;
4
+
5
+ use glib:: translate:: * ;
6
+
7
+ use crate :: ffi;
8
+
9
+ #[ doc( alias = "g_content_type_guess" ) ]
10
+ pub fn content_type_guess < ' a > (
11
+ filename : Option < impl AsRef < std:: path:: Path > > ,
12
+ data : impl Into < Option < & ' a [ u8 ] > > ,
13
+ ) -> ( glib:: GString , bool ) {
14
+ let data = data. into ( ) ;
15
+ let data_size = data. map_or ( 0 , |d| d. len ( ) ) ;
16
+ unsafe {
17
+ let mut result_uncertain = std:: mem:: MaybeUninit :: uninit ( ) ;
18
+ let ret = from_glib_full ( ffi:: g_content_type_guess (
19
+ filename. as_ref ( ) . map ( |p| p. as_ref ( ) ) . to_glib_none ( ) . 0 ,
20
+ data. map_or ( ptr:: null ( ) , |d| d. to_glib_none ( ) . 0 ) ,
21
+ data_size,
22
+ result_uncertain. as_mut_ptr ( ) ,
23
+ ) ) ;
24
+ ( ret, from_glib ( result_uncertain. assume_init ( ) ) )
25
+ }
26
+ }
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ mod cancellable;
22
22
pub use cancellable:: CancelledHandlerId ;
23
23
mod cancellable_future;
24
24
pub use crate :: cancellable_future:: { CancellableFuture , Cancelled } ;
25
+ mod content_type;
25
26
mod converter;
26
27
mod credentials;
27
28
mod data_input_stream;
@@ -116,6 +117,7 @@ pub mod builders {
116
117
117
118
pub mod functions {
118
119
pub use super :: auto:: functions:: * ;
120
+ pub use super :: content_type:: content_type_guess;
119
121
}
120
122
121
123
pub use crate :: auto:: * ;
Original file line number Diff line number Diff line change
1
+ // Take a look at the license at the top of the repository in the LICENSE file.
2
+
3
+ #[ cfg( unix) ]
4
+ #[ test]
5
+ fn test_content_type_guess ( ) {
6
+ // We only test for directory and file without extension here as we can't guarantee the
7
+ // CI runners will have any mimetypes installed.
8
+ let ret: ( glib:: GString , bool ) =
9
+ gio:: functions:: content_type_guess ( Some ( std:: path:: Path :: new ( "test/" ) ) , None ) ;
10
+ assert_eq ! ( ret. 0 , "inode/directory" ) ;
11
+
12
+ let ret: ( glib:: GString , bool ) =
13
+ gio:: functions:: content_type_guess ( Some ( std:: path:: Path :: new ( "test" ) ) , None ) ;
14
+ assert_eq ! ( ret. 0 , "application/octet-stream" ) ;
15
+ }
You can’t perform that action at this time.
0 commit comments