Skip to content

Commit 5d13156

Browse files
committed
glib: Add bindings for g_intern_string() and g_intern_static_string() to GStr
1 parent 9ce31b9 commit 5d13156

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

glib/src/gstring.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,39 @@ impl GStr {
289289
}
290290
}
291291
pub const NONE: Option<&'static GStr> = None;
292+
293+
// rustdoc-stripper-ignore-next
294+
/// Interns the string and returns the canonical representation.
295+
#[inline]
296+
#[doc(alias = "g_intern_string")]
297+
pub fn intern(&self) -> &'static GStr {
298+
unsafe {
299+
let s = ffi::g_intern_string(self.to_glib_none().0);
300+
GStr::from_ptr(s)
301+
}
302+
}
303+
304+
// rustdoc-stripper-ignore-next
305+
/// Interns the `'static` string and returns the canonical representation.
306+
#[inline]
307+
#[doc(alias = "g_intern_static_string")]
308+
pub fn intern_static(&'static self) -> &'static GStr {
309+
unsafe {
310+
let s = ffi::g_intern_static_string(self.to_glib_none().0);
311+
GStr::from_ptr(s)
312+
}
313+
}
314+
315+
// rustdoc-stripper-ignore-next
316+
/// Interns the string and returns the canonical representation.
317+
#[inline]
318+
#[doc(alias = "g_intern_string")]
319+
pub fn intern_from_str(s: impl AsRef<str>) -> &'static GStr {
320+
unsafe {
321+
let s = ffi::g_intern_string(s.as_ref().to_glib_none().0);
322+
GStr::from_ptr(s)
323+
}
324+
}
292325
}
293326

294327
// rustdoc-stripper-ignore-next

0 commit comments

Comments
 (0)