From 436215365998c0bee9c29b664ccb13170654aed8 Mon Sep 17 00:00:00 2001 From: Tin Svagelj Date: Thu, 31 Aug 2023 16:33:43 +0200 Subject: [PATCH] Fix debug feature Add explicit feature requirement for AllocationTracker Signed-off-by: Tin Svagelj --- src/lib.rs | 5 ++++- src/tracker.rs | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0786ec7..dc28208 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -347,7 +347,10 @@ impl ContiguousMemoryStorage { } #[cfg(feature = "debug")] -impl core::fmt::Debug for ContiguousMemoryStorage { +impl core::fmt::Debug for ContiguousMemoryStorage +where + Impl::StorageState: core::fmt::Debug, +{ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("ContiguousMemoryStorage") .field("inner", &self.inner) diff --git a/src/tracker.rs b/src/tracker.rs index fcd40ab..cac31c8 100644 --- a/src/tracker.rs +++ b/src/tracker.rs @@ -3,23 +3,19 @@ use core::alloc::Layout; #[cfg(any(not(feature = "std")))] -use crate::types::*; +use crate::types::Vec; use crate::{error::ContiguousMemoryError, range::ByteRange}; /// A structure that keeps track of unused regions of memory within provided /// bounds. #[derive(Clone)] -#[cfg_attr(feature = "debug", derive(Debug))] pub struct AllocationTracker { size: usize, unused: Vec, } + impl AllocationTracker { /// Constructs a new `AllocationTracker` of the provided `size`. - /// - /// # Arguments - /// - /// * `size` - The total size of the memory region that will be tracked. pub fn new(size: usize) -> Self { let mut initial = Vec::new(); initial.push(ByteRange(0, size)); @@ -230,6 +226,16 @@ impl AllocationTracker { } } +#[cfg(feature = "debug")] +impl core::fmt::Debug for AllocationTracker { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("AllocationTracker") + .field("size", &self.size) + .field("unused", &self.unused) + .finish() + } +} + #[cfg(test)] mod tests { use super::*;