Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
9 changes: 9 additions & 0 deletions src/slice/share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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> {
Expand Down
9 changes: 9 additions & 0 deletions src/slice/unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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> {
Expand Down
9 changes: 9 additions & 0 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -55,6 +57,13 @@ const _BUILTIN_TRAITS: () = {
self.as_slice()
}
}

#[cfg(feature = "std")]
impl<T: fmt::Debug> fmt::Debug for NonEmptyVec<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
fmt::Debug::fmt(self.as_slice(), f)
}
}
};

impl<T: Sized> NonEmptyVec<T> {
Expand Down