gio/auto/file_attribute_matcher.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::translate::*;
7
8glib::wrapper! {
9 /// Determines if a string matches a file attribute.
10 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
11 pub struct FileAttributeMatcher(Shared<ffi::GFileAttributeMatcher>);
12
13 match fn {
14 ref => |ptr| ffi::g_file_attribute_matcher_ref(ptr),
15 unref => |ptr| ffi::g_file_attribute_matcher_unref(ptr),
16 type_ => || ffi::g_file_attribute_matcher_get_type(),
17 }
18}
19
20impl FileAttributeMatcher {
21 /// Creates a new file attribute matcher, which matches attributes
22 /// against a given string. #GFileAttributeMatchers are reference
23 /// counted structures, and are created with a reference count of 1. If
24 /// the number of references falls to 0, the #GFileAttributeMatcher is
25 /// automatically destroyed.
26 ///
27 /// The @attributes string should be formatted with specific keys separated
28 /// from namespaces with a double colon. Several "namespace::key" strings may be
29 /// concatenated with a single comma (e.g. "standard::type,standard::is-hidden").
30 /// The wildcard "*" may be used to match all keys and namespaces, or
31 /// "namespace::*" will match all keys in a given namespace.
32 ///
33 /// ## Examples of file attribute matcher strings and results
34 ///
35 /// - `"*"`: matches all attributes.
36 /// - `"standard::is-hidden"`: matches only the key is-hidden in the
37 /// standard namespace.
38 /// - `"standard::type,unix::*"`: matches the type key in the standard
39 /// namespace and all keys in the unix namespace.
40 /// ## `attributes`
41 /// an attribute string to match.
42 ///
43 /// # Returns
44 ///
45 /// a #GFileAttributeMatcher
46 #[doc(alias = "g_file_attribute_matcher_new")]
47 pub fn new(attributes: &str) -> FileAttributeMatcher {
48 unsafe {
49 from_glib_full(ffi::g_file_attribute_matcher_new(
50 attributes.to_glib_none().0,
51 ))
52 }
53 }
54
55 /// Checks if the matcher will match all of the keys in a given namespace.
56 /// This will always return [`true`] if a wildcard character is in use (e.g. if
57 /// matcher was created with "standard::*" and @ns is "standard", or if matcher was created
58 /// using "*" and namespace is anything.)
59 ///
60 /// TODO: this is awkwardly worded.
61 /// ## `ns`
62 /// a string containing a file attribute namespace.
63 ///
64 /// # Returns
65 ///
66 /// [`true`] if the matcher matches all of the entries
67 /// in the given @ns, [`false`] otherwise.
68 #[doc(alias = "g_file_attribute_matcher_enumerate_namespace")]
69 pub fn enumerate_namespace(&self, ns: &str) -> bool {
70 unsafe {
71 from_glib(ffi::g_file_attribute_matcher_enumerate_namespace(
72 self.to_glib_none().0,
73 ns.to_glib_none().0,
74 ))
75 }
76 }
77
78 /// Checks if an attribute will be matched by an attribute matcher. If
79 /// the matcher was created with the "*" matching string, this function
80 /// will always return [`true`].
81 /// ## `attribute`
82 /// a file attribute key.
83 ///
84 /// # Returns
85 ///
86 /// [`true`] if @attribute matches @self. [`false`] otherwise.
87 #[doc(alias = "g_file_attribute_matcher_matches")]
88 pub fn matches(&self, attribute: &str) -> bool {
89 unsafe {
90 from_glib(ffi::g_file_attribute_matcher_matches(
91 self.to_glib_none().0,
92 attribute.to_glib_none().0,
93 ))
94 }
95 }
96
97 /// Checks if an attribute matcher only matches a given attribute. Always
98 /// returns [`false`] if "*" was used when creating the matcher.
99 /// ## `attribute`
100 /// a file attribute key.
101 ///
102 /// # Returns
103 ///
104 /// [`true`] if the matcher only matches @attribute. [`false`] otherwise.
105 #[doc(alias = "g_file_attribute_matcher_matches_only")]
106 pub fn matches_only(&self, attribute: &str) -> bool {
107 unsafe {
108 from_glib(ffi::g_file_attribute_matcher_matches_only(
109 self.to_glib_none().0,
110 attribute.to_glib_none().0,
111 ))
112 }
113 }
114
115 /// Subtracts all attributes of @subtract from @self and returns
116 /// a matcher that supports those attributes.
117 ///
118 /// Note that currently it is not possible to remove a single
119 /// attribute when the @self matches the whole namespace - or remove
120 /// a namespace or attribute when the matcher matches everything. This
121 /// is a limitation of the current implementation, but may be fixed
122 /// in the future.
123 /// ## `subtract`
124 /// The matcher to subtract
125 ///
126 /// # Returns
127 ///
128 /// A file attribute matcher matching all attributes of
129 /// @self that are not matched by @subtract
130 #[doc(alias = "g_file_attribute_matcher_subtract")]
131 #[must_use]
132 pub fn subtract(
133 &self,
134 subtract: Option<&FileAttributeMatcher>,
135 ) -> Option<FileAttributeMatcher> {
136 unsafe {
137 from_glib_full(ffi::g_file_attribute_matcher_subtract(
138 self.to_glib_none().0,
139 subtract.to_glib_none().0,
140 ))
141 }
142 }
143
144 /// Prints what the matcher is matching against. The format will be
145 /// equal to the format passed to g_file_attribute_matcher_new().
146 /// The output however, might not be identical, as the matcher may
147 /// decide to use a different order or omit needless parts.
148 ///
149 /// # Returns
150 ///
151 /// a string describing the attributes the matcher matches
152 /// against or [`None`] if @self was [`None`].
153 #[doc(alias = "g_file_attribute_matcher_to_string")]
154 #[doc(alias = "to_string")]
155 pub fn to_str(&self) -> glib::GString {
156 unsafe {
157 from_glib_full(ffi::g_file_attribute_matcher_to_string(
158 self.to_glib_none().0,
159 ))
160 }
161 }
162}
163
164impl std::fmt::Display for FileAttributeMatcher {
165 #[inline]
166 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
167 f.write_str(&self.to_str())
168 }
169}