Skip to content

Commit c4cf5e1

Browse files
committed
Add sys::bool_from_sys() convenience function
1 parent f24d1de commit c4cf5e1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

godot-ffi/src/conv.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,23 @@ pub fn u32_to_usize(i: u32) -> usize {
2525
unsafe { i.try_into().unwrap_unchecked() }
2626
}
2727

28-
/// Converts a rust-bool into a sys-bool.
28+
/// Converts a Rust-bool into a sys-bool.
2929
pub const fn bool_to_sys(value: bool) -> sys::GDExtensionBool {
3030
value as sys::GDExtensionBool
3131
}
3232

33+
/// Converts a sys-bool to Rust-bool.
34+
///
35+
/// # Panics
36+
/// If the value is not a valid sys-bool (0 or 1).
37+
pub fn bool_from_sys(value: sys::GDExtensionBool) -> bool {
38+
match value {
39+
SYS_TRUE => true,
40+
SYS_FALSE => false,
41+
_ => panic!("Invalid GDExtensionBool value: {}", value),
42+
}
43+
}
44+
3345
/// Convert a list into a pointer + length pair. Should be used together with [`ptr_list_from_sys`].
3446
///
3547
/// If `list_from_sys` is not called on this list then that will cause a memory leak.

0 commit comments

Comments
 (0)