Show byte and word length when Debug SizeClass
+use core::fmt::{self, Debug};
use core::mem;
/// A wrapper around `usize` values which define a size class
/// in terms of its size in words
-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct SizeClass(usize);
+
impl SizeClass {
#[inline]
pub const fn new(words: usize) -> Self {
@@ -27,6 +29,15 @@ impl SizeClass {
}
}
+impl Debug for SizeClass {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ f.debug_struct("SizeClass")
+ .field("byte_len", &self.to_bytes())
+ .field("word_len", &self.as_words())
+ .finish()
+ }
+}
+
/// Represents a type which can map allocation sizes to size class sizes
pub trait SizeClassIndex {
/// Given a SizeClass returned by `size_class_for`, this returns the
