Skip to content

Commit aa1327b

Browse files
authored
Merge pull request #1400 from sdroege/value-from-static-string
glib: Add bindings for `g_value_set_static_string()`
2 parents 1c3625e + 224d8fd commit aa1327b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

glib/src/value.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ use crate::{
5858
prelude::*,
5959
translate::*,
6060
types::{Pointee, Pointer, Type},
61+
GStr,
6162
};
6263

6364
// rustdoc-stripper-ignore-next
@@ -537,6 +538,33 @@ impl Value {
537538
unsafe { Value::from_type_unchecked(T::Type::static_type()) }
538539
}
539540

541+
// rustdoc-stripper-ignore-next
542+
/// Creates a new `String`-typed `Value` from a `'static` string.
543+
#[inline]
544+
#[doc(alias = "g_value_set_static_string")]
545+
pub fn from_static_str(s: &'static GStr) -> Self {
546+
unsafe {
547+
let mut v = Self::from_type_unchecked(Type::STRING);
548+
gobject_ffi::g_value_set_static_string(v.to_glib_none_mut().0, s.as_ptr());
549+
v
550+
}
551+
}
552+
553+
#[cfg(feature = "v2_66")]
554+
#[cfg_attr(docsrs, doc(cfg(feature = "v2_66")))]
555+
// rustdoc-stripper-ignore-next
556+
/// Creates a new `String`-typed `Value` from a `'static` string that is also assumed to be
557+
/// interned.
558+
#[inline]
559+
#[doc(alias = "g_value_set_interned_string")]
560+
pub fn from_interned_str(s: &'static GStr) -> Self {
561+
unsafe {
562+
let mut v = Self::from_type_unchecked(Type::STRING);
563+
gobject_ffi::g_value_set_interned_string(v.to_glib_none_mut().0, s.as_ptr());
564+
v
565+
}
566+
}
567+
540568
// rustdoc-stripper-ignore-next
541569
/// Tries to get a value of type `T`.
542570
///

0 commit comments

Comments
 (0)