|
1 | | -use std::marker::PhantomData; |
| 1 | +use std::{ |
| 2 | + fmt::{Debug, Formatter, Result}, |
| 3 | + marker::PhantomData, |
| 4 | +}; |
2 | 5 |
|
3 | 6 | use libbitcoinkernel_sys::{ |
4 | 7 | btck_BlockValidationResult, btck_BlockValidationResult_CACHED_INVALID, |
@@ -230,6 +233,15 @@ impl FromMutPtr<btck_BlockValidationState> for BlockValidationState { |
230 | 233 |
|
231 | 234 | impl BlockValidationStateExt for BlockValidationState {} |
232 | 235 |
|
| 236 | +impl Debug for BlockValidationState { |
| 237 | + fn fmt(&self, f: &mut Formatter<'_>) -> Result { |
| 238 | + f.debug_struct("BlockValidationState") |
| 239 | + .field("mode", &self.mode()) |
| 240 | + .field("result", &self.result()) |
| 241 | + .finish() |
| 242 | + } |
| 243 | +} |
| 244 | + |
233 | 245 | impl Clone for BlockValidationState { |
234 | 246 | fn clone(&self) -> Self { |
235 | 247 | BlockValidationState { |
@@ -275,6 +287,15 @@ impl<'a> Clone for BlockValidationStateRef<'a> { |
275 | 287 | } |
276 | 288 | } |
277 | 289 |
|
| 290 | +impl<'a> Debug for BlockValidationStateRef<'a> { |
| 291 | + fn fmt(&self, f: &mut Formatter<'_>) -> Result { |
| 292 | + f.debug_struct("BlockValidationStateRef") |
| 293 | + .field("mode", &self.mode()) |
| 294 | + .field("result", &self.result()) |
| 295 | + .finish() |
| 296 | + } |
| 297 | +} |
| 298 | + |
278 | 299 | impl<'a> BlockValidationStateExt for BlockValidationStateRef<'a> {} |
279 | 300 |
|
280 | 301 | #[cfg(test)] |
@@ -621,4 +642,25 @@ mod tests { |
621 | 642 | assert_eq!(result, back); |
622 | 643 | } |
623 | 644 | } |
| 645 | + |
| 646 | + #[test] |
| 647 | + fn test_block_validation_state_debug() { |
| 648 | + let state = BlockValidationState::new(); |
| 649 | + let s = format!("{:?}", state); |
| 650 | + assert!(s.contains("BlockValidationState")); |
| 651 | + assert!(s.contains("mode")); |
| 652 | + assert!(s.contains("result")); |
| 653 | + } |
| 654 | + |
| 655 | + #[test] |
| 656 | + fn test_block_validation_state_ref_debug() { |
| 657 | + use crate::ffi::sealed::FromPtr; |
| 658 | + let state = BlockValidationState::new(); |
| 659 | + let state_ref: BlockValidationStateRef<'_> = |
| 660 | + unsafe { BlockValidationStateRef::from_ptr(state.as_ptr()) }; |
| 661 | + let s = format!("{:?}", state_ref); |
| 662 | + assert!(s.contains("BlockValidationStateRef")); |
| 663 | + assert!(s.contains("mode")); |
| 664 | + assert!(s.contains("result")); |
| 665 | + } |
624 | 666 | } |
0 commit comments