diff --git a/gio/Gir.toml b/gio/Gir.toml index 7448735b816d..cfa9a751f01c 100644 --- a/gio/Gir.toml +++ b/gio/Gir.toml @@ -249,9 +249,9 @@ status = "generate" ignore = true [[object.function]] name = "content_type_guess" - # implemented manually until gir generates nullable array parameters - # https://github.com/gtk-rs/gir/issues/1133 - manual = true + [[object.function.parameter]] + name = "filename" + string_type = "filename" [[object]] name = "Gio.ActionGroup" diff --git a/gio/src/auto/functions.rs b/gio/src/auto/functions.rs index 5a3df411f7dc..aeecbd2a3814 100644 --- a/gio/src/auto/functions.rs +++ b/gio/src/auto/functions.rs @@ -178,6 +178,24 @@ pub fn content_type_get_symbolic_icon(type_: &str) -> Icon { } } +#[doc(alias = "g_content_type_guess")] +pub fn content_type_guess( + filename: Option>, + data: &[u8], +) -> (glib::GString, bool) { + let data_size = data.len() as _; + unsafe { + let mut result_uncertain = std::mem::MaybeUninit::uninit(); + let ret = from_glib_full(ffi::g_content_type_guess( + filename.as_ref().map(|p| p.as_ref()).to_glib_none().0, + data.to_glib_none().0, + data_size, + result_uncertain.as_mut_ptr(), + )); + (ret, from_glib(result_uncertain.assume_init())) + } +} + #[doc(alias = "g_content_type_guess_for_tree")] pub fn content_type_guess_for_tree(root: &impl IsA) -> Vec { unsafe { diff --git a/gio/src/content_type.rs b/gio/src/content_type.rs deleted file mode 100644 index 37a8d13bad08..000000000000 --- a/gio/src/content_type.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Take a look at the license at the top of the repository in the LICENSE file. - -use std::ptr; - -use glib::translate::*; - -use crate::ffi; - -#[doc(alias = "g_content_type_guess")] -pub fn content_type_guess<'a>( - filename: Option>, - data: impl Into>, -) -> (glib::GString, bool) { - let data = data.into(); - let data_size = data.map_or(0, |d| d.len()); - unsafe { - let mut result_uncertain = std::mem::MaybeUninit::uninit(); - let ret = from_glib_full(ffi::g_content_type_guess( - filename.as_ref().map(|p| p.as_ref()).to_glib_none().0, - data.map_or(ptr::null(), |d| d.to_glib_none().0), - data_size, - result_uncertain.as_mut_ptr(), - )); - (ret, from_glib(result_uncertain.assume_init())) - } -} diff --git a/gio/src/lib.rs b/gio/src/lib.rs index f11e3fb2338a..fd0765fa4a77 100644 --- a/gio/src/lib.rs +++ b/gio/src/lib.rs @@ -22,7 +22,6 @@ mod cancellable; pub use cancellable::CancelledHandlerId; mod cancellable_future; pub use crate::cancellable_future::{CancellableFuture, Cancelled}; -mod content_type; mod converter; mod credentials; mod data_input_stream; @@ -117,7 +116,6 @@ pub mod builders { pub mod functions { pub use super::auto::functions::*; - pub use super::content_type::content_type_guess; } pub use crate::auto::*; diff --git a/gio/tests/content_type.rs b/gio/tests/content_type.rs deleted file mode 100644 index b05193430e72..000000000000 --- a/gio/tests/content_type.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Take a look at the license at the top of the repository in the LICENSE file. - -#[cfg(unix)] -#[test] -fn test_content_type_guess() { - // We only test for directory and file without extension here as we can't guarantee the - // CI runners will have any mimetypes installed. - let ret: (glib::GString, bool) = - gio::functions::content_type_guess(Some(std::path::Path::new("test/")), None); - assert_eq!(ret.0, "inode/directory"); - - let ret: (glib::GString, bool) = - gio::functions::content_type_guess(Some(std::path::Path::new("test")), None); - assert_eq!(ret.0, "application/octet-stream"); -}