gio/auto/
tls_file_database.rs1use crate::{ffi, TlsDatabase};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GTlsFileDatabase")]
15 pub struct TlsFileDatabase(Interface<ffi::GTlsFileDatabase, ffi::GTlsFileDatabaseInterface>) @requires TlsDatabase;
16
17 match fn {
18 type_ => || ffi::g_tls_file_database_get_type(),
19 }
20}
21
22impl TlsFileDatabase {
23 pub const NONE: Option<&'static TlsFileDatabase> = None;
24
25 #[doc(alias = "g_tls_file_database_new")]
26 pub fn new(anchors: impl AsRef<std::path::Path>) -> Result<TlsFileDatabase, glib::Error> {
27 unsafe {
28 let mut error = std::ptr::null_mut();
29 let ret = ffi::g_tls_file_database_new(anchors.as_ref().to_glib_none().0, &mut error);
30 if error.is_null() {
31 Ok(from_glib_full(ret))
32 } else {
33 Err(from_glib_full(error))
34 }
35 }
36 }
37}
38
39pub trait TlsFileDatabaseExt: IsA<TlsFileDatabase> + 'static {
40 fn anchors(&self) -> Option<glib::GString> {
41 ObjectExt::property(self.as_ref(), "anchors")
42 }
43
44 fn set_anchors(&self, anchors: Option<&str>) {
45 ObjectExt::set_property(self.as_ref(), "anchors", anchors)
46 }
47
48 #[doc(alias = "anchors")]
49 fn connect_anchors_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
50 unsafe extern "C" fn notify_anchors_trampoline<
51 P: IsA<TlsFileDatabase>,
52 F: Fn(&P) + 'static,
53 >(
54 this: *mut ffi::GTlsFileDatabase,
55 _param_spec: glib::ffi::gpointer,
56 f: glib::ffi::gpointer,
57 ) {
58 let f: &F = &*(f as *const F);
59 f(TlsFileDatabase::from_glib_borrow(this).unsafe_cast_ref())
60 }
61 unsafe {
62 let f: Box_<F> = Box_::new(f);
63 connect_raw(
64 self.as_ptr() as *mut _,
65 c"notify::anchors".as_ptr() as *const _,
66 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
67 notify_anchors_trampoline::<Self, F> as *const (),
68 )),
69 Box_::into_raw(f),
70 )
71 }
72 }
73}
74
75impl<O: IsA<TlsFileDatabase>> TlsFileDatabaseExt for O {}