soup/auto/
cache.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use crate::{ffi, CacheType, SessionFeature};
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10    #[doc(alias = "SoupCache")]
11    pub struct Cache(Object<ffi::SoupCache, ffi::SoupCacheClass>) @implements SessionFeature;
12
13    match fn {
14        type_ => || ffi::soup_cache_get_type(),
15    }
16}
17
18impl Cache {
19    pub const NONE: Option<&'static Cache> = None;
20
21    #[doc(alias = "soup_cache_new")]
22    pub fn new(cache_dir: Option<&str>, cache_type: CacheType) -> Cache {
23        assert_initialized_main_thread!();
24        unsafe {
25            from_glib_full(ffi::soup_cache_new(
26                cache_dir.to_glib_none().0,
27                cache_type.into_glib(),
28            ))
29        }
30    }
31
32    // rustdoc-stripper-ignore-next
33    /// Creates a new builder-pattern struct instance to construct [`Cache`] objects.
34    ///
35    /// This method returns an instance of [`CacheBuilder`](crate::builders::CacheBuilder) which can be used to create [`Cache`] objects.
36    pub fn builder() -> CacheBuilder {
37        CacheBuilder::new()
38    }
39}
40
41impl Default for Cache {
42    fn default() -> Self {
43        glib::object::Object::new::<Self>()
44    }
45}
46
47// rustdoc-stripper-ignore-next
48/// A [builder-pattern] type to construct [`Cache`] objects.
49///
50/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
51#[must_use = "The builder must be built to be used"]
52pub struct CacheBuilder {
53    builder: glib::object::ObjectBuilder<'static, Cache>,
54}
55
56impl CacheBuilder {
57    fn new() -> Self {
58        Self {
59            builder: glib::object::Object::builder(),
60        }
61    }
62
63    pub fn cache_dir(self, cache_dir: impl Into<glib::GString>) -> Self {
64        Self {
65            builder: self.builder.property("cache-dir", cache_dir.into()),
66        }
67    }
68
69    pub fn cache_type(self, cache_type: CacheType) -> Self {
70        Self {
71            builder: self.builder.property("cache-type", cache_type),
72        }
73    }
74
75    // rustdoc-stripper-ignore-next
76    /// Build the [`Cache`].
77    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
78    pub fn build(self) -> Cache {
79        self.builder.build()
80    }
81}
82
83mod sealed {
84    pub trait Sealed {}
85    impl<T: super::IsA<super::Cache>> Sealed for T {}
86}
87
88pub trait CacheExt: IsA<Cache> + sealed::Sealed + 'static {
89    #[doc(alias = "soup_cache_clear")]
90    fn clear(&self) {
91        unsafe {
92            ffi::soup_cache_clear(self.as_ref().to_glib_none().0);
93        }
94    }
95
96    #[doc(alias = "soup_cache_dump")]
97    fn dump(&self) {
98        unsafe {
99            ffi::soup_cache_dump(self.as_ref().to_glib_none().0);
100        }
101    }
102
103    #[doc(alias = "soup_cache_flush")]
104    fn flush(&self) {
105        unsafe {
106            ffi::soup_cache_flush(self.as_ref().to_glib_none().0);
107        }
108    }
109
110    #[doc(alias = "soup_cache_get_max_size")]
111    #[doc(alias = "get_max_size")]
112    fn max_size(&self) -> u32 {
113        unsafe { ffi::soup_cache_get_max_size(self.as_ref().to_glib_none().0) }
114    }
115
116    #[doc(alias = "soup_cache_load")]
117    fn load(&self) {
118        unsafe {
119            ffi::soup_cache_load(self.as_ref().to_glib_none().0);
120        }
121    }
122
123    #[doc(alias = "soup_cache_set_max_size")]
124    fn set_max_size(&self, max_size: u32) {
125        unsafe {
126            ffi::soup_cache_set_max_size(self.as_ref().to_glib_none().0, max_size);
127        }
128    }
129
130    #[doc(alias = "cache-dir")]
131    fn cache_dir(&self) -> Option<glib::GString> {
132        ObjectExt::property(self.as_ref(), "cache-dir")
133    }
134
135    #[doc(alias = "cache-type")]
136    fn cache_type(&self) -> CacheType {
137        ObjectExt::property(self.as_ref(), "cache-type")
138    }
139}
140
141impl<O: IsA<Cache>> CacheExt for O {}