/rust/registry/src/index.crates.io-1949cf8c6b5b557f/aws-lc-rs-1.14.1/src/debug.rs
Line | Count | Source |
1 | | // Copyright 2018 Trent Clarke. |
2 | | // SPDX-License-Identifier: ISC |
3 | | // Modifications copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
4 | | // SPDX-License-Identifier: Apache-2.0 OR ISC |
5 | | |
6 | | // Generates an implementation of the Debug trait for a type that defers to the |
7 | | // Debug implementation for a given field. |
8 | | |
9 | | #![allow(missing_docs)] |
10 | | |
11 | | macro_rules! derive_debug_via_id { |
12 | | ($typename:ident) => { |
13 | | impl ::core::fmt::Debug for $typename { |
14 | 0 | fn fmt(&self, f: &mut ::core::fmt::Formatter) -> Result<(), ::core::fmt::Error> { |
15 | 0 | ::core::fmt::Debug::fmt(&self.id, f) |
16 | 0 | } Unexecuted instantiation: <aws_lc_rs::aead::quic::Algorithm as core::fmt::Debug>::fmt Unexecuted instantiation: <aws_lc_rs::digest::Algorithm as core::fmt::Debug>::fmt Unexecuted instantiation: <aws_lc_rs::aead::Algorithm as core::fmt::Debug>::fmt |
17 | | } |
18 | | }; |
19 | | } |
20 | | pub(crate) use derive_debug_via_id; |
21 | | |
22 | | #[allow(unused_macros)] |
23 | | macro_rules! derive_debug_via_field { |
24 | | ($type:ty, $field:ident) => { |
25 | | derive_debug_via_field!($type, stringify!($type), $field); |
26 | | }; |
27 | | |
28 | | ($type:ty, $typename:expr, $field:ident) => { |
29 | | impl ::core::fmt::Debug for $type { |
30 | | fn fmt(&self, f: &mut ::core::fmt::Formatter) -> Result<(), ::core::fmt::Error> { |
31 | | f.debug_struct($typename) |
32 | | .field(stringify!($field), &self.$field) |
33 | | .finish() |
34 | | } |
35 | | } |
36 | | }; |
37 | | } |
38 | | |
39 | | // Generates an implementation of the Debug trait for a type that outputs the |
40 | | // hex encoding of the byte slice representation of the value. |
41 | | #[allow(unused_macros)] |
42 | | macro_rules! derive_debug_self_as_ref_hex_bytes { |
43 | | ($typename:ident) => { |
44 | | impl ::core::fmt::Debug for $typename { |
45 | | fn fmt(&self, f: &mut ::core::fmt::Formatter) -> Result<(), ::core::fmt::Error> { |
46 | | crate::debug::write_hex_tuple(f, stringify!($typename), self) |
47 | | } |
48 | | } |
49 | | }; |
50 | | } |
51 | | |
52 | 0 | pub(crate) fn write_hex_bytes( |
53 | 0 | fmt: &mut core::fmt::Formatter, |
54 | 0 | bytes: &[u8], |
55 | 0 | ) -> Result<(), core::fmt::Error> { |
56 | 0 | for byte in bytes { |
57 | 0 | write!(fmt, "{byte:02x}")?; |
58 | | } |
59 | 0 | Ok(()) |
60 | 0 | } |