Skip to content

Commit a2243b6

Browse files
committed
zephyr: work: Allow struct to have a additional fields
Structs in the C world assume zero initialization, and therefore adding fields is not considered an API change. Support this for an upcoming API change in the work queue config, by deriving default for these structs, and using this zero-init as a default. This should support fields being added to this struct. The rust code will zero init the unknown fields, which will have the same behavior as the C code. Signed-off-by: David Brown <[email protected]>
1 parent 174ded5 commit a2243b6

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

zephyr-sys/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ fn main() -> Result<()> {
7474
.clang_arg("-DRUST_BINDGEN")
7575
.clang_arg(format!("-I{}/lib/libc/minimal/include", zephyr_base))
7676
.derive_copy(false)
77+
.derive_default(true)
7778
.allowlist_function("k_.*")
7879
.allowlist_function("gpio_.*")
7980
.allowlist_function("flash_.*")

zephyr/src/work.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ use core::{
105105
ffi::{c_int, c_uint, CStr},
106106
mem,
107107
pin::Pin,
108-
ptr,
109108
};
110109

111110
use zephyr_sys::{
@@ -138,11 +137,7 @@ impl WorkQueueBuilder {
138137
/// Construct a new WorkQueueBuilder with default values.
139138
pub fn new() -> Self {
140139
Self {
141-
config: k_work_queue_config {
142-
name: ptr::null(),
143-
no_yield: false,
144-
essential: false,
145-
},
140+
config: Default::default(),
146141
priority: 0,
147142
}
148143
}

0 commit comments

Comments
 (0)