Skip to content

Commit

Permalink
Merge pull request #1400 from sdroege/value-from-static-string
Browse files Browse the repository at this point in the history
glib: Add bindings for `g_value_set_static_string()`
  • Loading branch information
sdroege committed May 15, 2024
2 parents 1c3625e + 224d8fd commit aa1327b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions glib/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use crate::{
prelude::*,
translate::*,
types::{Pointee, Pointer, Type},
GStr,
};

// rustdoc-stripper-ignore-next
Expand Down Expand Up @@ -537,6 +538,33 @@ impl Value {
unsafe { Value::from_type_unchecked(T::Type::static_type()) }
}

// rustdoc-stripper-ignore-next
/// Creates a new `String`-typed `Value` from a `'static` string.
#[inline]
#[doc(alias = "g_value_set_static_string")]
pub fn from_static_str(s: &'static GStr) -> Self {
unsafe {
let mut v = Self::from_type_unchecked(Type::STRING);
gobject_ffi::g_value_set_static_string(v.to_glib_none_mut().0, s.as_ptr());
v
}
}

#[cfg(feature = "v2_66")]
#[cfg_attr(docsrs, doc(cfg(feature = "v2_66")))]
// rustdoc-stripper-ignore-next
/// Creates a new `String`-typed `Value` from a `'static` string that is also assumed to be
/// interned.
#[inline]
#[doc(alias = "g_value_set_interned_string")]
pub fn from_interned_str(s: &'static GStr) -> Self {
unsafe {
let mut v = Self::from_type_unchecked(Type::STRING);
gobject_ffi::g_value_set_interned_string(v.to_glib_none_mut().0, s.as_ptr());
v
}
}

// rustdoc-stripper-ignore-next
/// Tries to get a value of type `T`.
///
Expand Down

0 comments on commit aa1327b

Please sign in to comment.