Skip to content

Commit d2fc503

Browse files
committed
glib: Allow variable expansion in fmt strings passed to result_from_gboolean
1 parent 378180a commit d2fc503

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

glib/src/error.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -177,26 +177,30 @@ macro_rules! bool_error(
177177

178178
#[macro_export]
179179
macro_rules! result_from_gboolean(
180-
// Plain strings
181-
($ffi_bool:expr, $msg:expr) => {{
182-
$crate::BoolError::from_glib(
183-
$ffi_bool,
184-
$msg,
185-
file!(),
186-
$crate::function_name!(),
187-
line!(),
188-
)
189-
}};
190-
191-
// Format strings
192180
($ffi_bool:expr, $($msg:tt)*) => {{
193-
$crate::BoolError::from_glib(
194-
$ffi_bool,
195-
format!($($msg)*),
196-
file!(),
197-
$crate::function_name!(),
198-
line!(),
199-
)
181+
match ::std::format_args!($($msg)*) {
182+
formatted => {
183+
if let Some(s) = formatted.as_str() {
184+
$crate::BoolError::from_glib(
185+
$ffi_bool,
186+
s,
187+
file!(),
188+
$crate::function_name!(),
189+
line!(),
190+
)
191+
} else {
192+
$crate::BoolError::from_glib(
193+
$ffi_bool,
194+
formatted.to_string(),
195+
file!(),
196+
$crate::function_name!(),
197+
line!(),
198+
)
199+
}
200+
}
201+
}
202+
203+
200204
}};
201205
);
202206

0 commit comments

Comments
 (0)