Skip to content

Commit 3d36740

Browse files
committed
zephyr-sys: derive Copy/Clone for z_spinlock_key
This type is used like a data item, so derive Copy/Clone for it. This also adds some macros to make this easier to add additional types later. Signed-off-by: David Brown <[email protected]>
1 parent 3f71ea7 commit 3d36740

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

zephyr-sys/src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,30 @@
2020
#![allow(rustdoc::broken_intra_doc_links)]
2121

2222
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
23+
24+
// We have directed bindgen to not generate copy for any times. It unfortunately doesn't have an
25+
// easy mechanism to enable just for a few types.
26+
27+
// Fortunately, it isn't difficult to mostly auto-derive copy/clone.
28+
macro_rules! derive_clone {
29+
($($t:ty),+ $(,)?) => {
30+
$(
31+
impl Clone for $t {
32+
fn clone(&self) -> $t {
33+
*self
34+
}
35+
}
36+
)+
37+
};
38+
}
39+
40+
macro_rules! derive_copy {
41+
($($t:ty),+ $(,)?) => {
42+
$(
43+
impl Copy for $t {}
44+
)+
45+
}
46+
}
47+
48+
derive_copy!(z_spinlock_key);
49+
derive_clone!(z_spinlock_key);

0 commit comments

Comments
 (0)