Skip to content

Commit

Permalink
Fix debug feature
Browse files Browse the repository at this point in the history
Add explicit feature requirement for AllocationTracker

Signed-off-by: Tin Svagelj <tin.svagelj@live.com>
  • Loading branch information
Caellian committed Aug 31, 2023
1 parent 30388d7 commit 4362153
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ impl ContiguousMemoryStorage<ImplUnsafe> {
}

#[cfg(feature = "debug")]
impl<Impl: ImplDetails = ImplDefault> core::fmt::Debug for ContiguousMemoryStorage<Impl> {
impl<Impl: ImplDetails> core::fmt::Debug for ContiguousMemoryStorage<Impl>
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)
Expand Down
18 changes: 12 additions & 6 deletions src/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ByteRange>,
}

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));
Expand Down Expand Up @@ -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::*;
Expand Down

0 comments on commit 4362153

Please sign in to comment.