Skip to content

Commit

Permalink
merge: pull request #1 from RalfJung/packed
Browse files Browse the repository at this point in the history
avoid bindgen-generated Debug impl of dtls_hello_verify_t
  • Loading branch information
pulsastrix committed Nov 19, 2022
2 parents c4c3123 + b163784 commit dfff31a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tinydtls-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ fn main() {
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.default_enum_style(EnumVariation::Rust { non_exhaustive: true })
.rustfmt_bindings(false)
// Some types cannot have `Debug` as they are packed and have non-Copy fields.
.no_debug("dtls_hello_verify_t")
// Declarations that should be part of the bindings.
.allowlist_function("dtls_.*")
.allowlist_type("dtls_.*")
Expand Down
15 changes: 15 additions & 0 deletions tinydtls-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#![allow(non_upper_case_globals)]
#![allow(deref_nullptr)]

use std::fmt;

use libc::{sockaddr, sockaddr_in, sockaddr_in6, sockaddr_storage, socklen_t};

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

// For backwards-compatibility, we add a Debug implementation of dtls_hello_verify_t.
// (Automatic derive stopped working with https://github.com/rust-lang/rust/pull/104429.)
impl fmt::Debug for dtls_hello_verify_t {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self { version, cookie_length, cookie } = self;
fmt.debug_struct("dtls_hello_verify_t")
.field("version", version)
.field("cookie_length", cookie_length)
.field("cookie", cookie)
.finish()
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit dfff31a

Please sign in to comment.