diff --git a/src/lib.rs b/src/lib.rs index bf77bab..a236e2b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,9 @@ More introduction is in the README. #![doc(html_root_url = "https://docs.rs/oom/0.3.0")] #![warn(rust_2018_idioms)] +#[cfg(feature = "std")] +extern crate std; + #[cfg(feature = "slice")] mod slice; #[cfg(feature = "vec")] diff --git a/src/slice/share.rs b/src/slice/share.rs index badf6d7..ae1dacb 100644 --- a/src/slice/share.rs +++ b/src/slice/share.rs @@ -3,6 +3,8 @@ use core::hint::unreachable_unchecked; use core::mem::size_of; use core::num::NonZeroUsize; use core::slice; +#[cfg(feature = "std")] +use std::fmt; // FIXME: Use unsized `[T]` as inner type (see loaf crate) // and return `&NonEmptySlice` or `&mut NonEmptySlice`. @@ -57,6 +59,13 @@ const _BUILTIN_TRAITS: () = { self.as_slice() } } + + #[cfg(feature = "std")] + impl<'a, T: fmt::Debug> fmt::Debug for NonEmptySlice<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + fmt::Debug::fmt(self.as_slice(), f) + } + } }; impl<'a, T: Sized> NonEmptySlice<'a, T> { diff --git a/src/slice/unique.rs b/src/slice/unique.rs index 665b83d..ee803af 100644 --- a/src/slice/unique.rs +++ b/src/slice/unique.rs @@ -3,6 +3,8 @@ use core::hint::unreachable_unchecked; use core::mem::size_of; use core::num::NonZeroUsize; use core::slice; +#[cfg(feature = "std")] +use std::fmt; /// A non-empty mutable slice type, counterpart of `&mut [T]`. pub struct NonEmptyMutSlice<'a, T: Sized> { @@ -45,6 +47,13 @@ const _BUILTIN_TRAITS: () = { self.as_slice() } } + + #[cfg(feature = "std")] + impl<'a, T: fmt::Debug> fmt::Debug for NonEmptyMutSlice<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + fmt::Debug::fmt(self.as_slice(), f) + } + } }; impl<'a, T: Sized> NonEmptyMutSlice<'a, T> { diff --git a/src/vec.rs b/src/vec.rs index d37de9b..8b5b1d3 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -5,6 +5,8 @@ use core::cmp::Ordering; use core::hint::unreachable_unchecked; use core::mem::size_of; use core::num::NonZeroUsize; +#[cfg(feature = "std")] +use std::fmt; use crate::{NonEmptyMutSlice, NonEmptySlice}; @@ -55,6 +57,13 @@ const _BUILTIN_TRAITS: () = { self.as_slice() } } + + #[cfg(feature = "std")] + impl fmt::Debug for NonEmptyVec { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + fmt::Debug::fmt(self.as_slice(), f) + } + } }; impl NonEmptyVec {