gio/
content_type.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::ptr;
4
5use glib::translate::*;
6
7use crate::ffi;
8
9#[doc(alias = "g_content_type_guess")]
10pub 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}