From 35b5a043c11b59d167dc96dcf68e92e31c1b126e Mon Sep 17 00:00:00 2001 From: Zander Brown Date: Tue, 12 Dec 2023 03:25:40 +0000 Subject: [PATCH] glib: Add get_transformed to Value Like transform(), but actually gives you T instead of a new Value, which is probably what you wanted --- glib/src/value.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/glib/src/value.rs b/glib/src/value.rs index a462b84a735c..cbe2e40e40e5 100644 --- a/glib/src/value.rs +++ b/glib/src/value.rs @@ -565,6 +565,22 @@ impl Value { } } + // rustdoc-stripper-ignore-next + /// Tries to transform the value into the target type + #[doc(alias = "g_value_transform")] + pub fn get_transformed(&self) -> Result { + self.transform::().and_then(|v| { + v.get().map_err(|e| { + crate::bool_error!( + "Can't transform value of type '{}' into '{}': {}", + self.type_(), + T::Type::static_type(), + e + ) + }) + }) + } + // rustdoc-stripper-ignore-next /// Returns `true` if the type of the value corresponds to `T` /// or is a sub-type of `T`.