Skip to content

Commit b163784

Browse files
committed
avoid bindgen-generated Debug impl of dtls_hello_verify_t
1 parent c4c3123 commit b163784

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tinydtls-sys/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ fn main() {
112112
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
113113
.default_enum_style(EnumVariation::Rust { non_exhaustive: true })
114114
.rustfmt_bindings(false)
115+
// Some types cannot have `Debug` as they are packed and have non-Copy fields.
116+
.no_debug("dtls_hello_verify_t")
115117
// Declarations that should be part of the bindings.
116118
.allowlist_function("dtls_.*")
117119
.allowlist_type("dtls_.*")

tinydtls-sys/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#![allow(non_upper_case_globals)]
1313
#![allow(deref_nullptr)]
1414

15+
use std::fmt;
16+
1517
use libc::{sockaddr, sockaddr_in, sockaddr_in6, sockaddr_storage, socklen_t};
1618

1719
#[cfg(target_family = "windows")]
@@ -32,6 +34,19 @@ pub unsafe fn dtls_set_handler(ctx: *mut dtls_context_t, h: *mut dtls_handler_t)
3234
(*ctx).h = h;
3335
}
3436

37+
// For backwards-compatibility, we add a Debug implementation of dtls_hello_verify_t.
38+
// (Automatic derive stopped working with https://github.com/rust-lang/rust/pull/104429.)
39+
impl fmt::Debug for dtls_hello_verify_t {
40+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
41+
let Self { version, cookie_length, cookie } = self;
42+
fmt.debug_struct("dtls_hello_verify_t")
43+
.field("version", version)
44+
.field("cookie_length", cookie_length)
45+
.field("cookie", cookie)
46+
.finish()
47+
}
48+
}
49+
3550
#[cfg(test)]
3651
mod tests {
3752
use super::*;

0 commit comments

Comments
 (0)