#![cfg_attr(not(feature = "std"), no_std)]
#![doc(html_root_url = "https://docs.rs/not_empty/0.1.3")]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![deny(missing_docs)]
#![deny(clippy::pedantic)]
#![allow(clippy::module_name_repetitions, clippy::wildcard_imports)]
#[cfg(all(feature = "alloc", feature = "std"))]
compile_error!("`not_empty` cannot have both `alloc` and `std` features enabled");
#[cfg(any(feature = "alloc", feature = "std"))]
mod alloc;
#[cfg(any(feature = "alloc", feature = "std"))]
mod iter;
pub mod slice;
#[cfg(any(feature = "alloc", feature = "std"))]
mod vec;
#[cfg(any(feature = "alloc", feature = "std"))]
pub use iter::IteratorExt;
#[doc(inline)]
pub use slice::NonEmptySlice;
#[cfg(any(feature = "alloc", feature = "std"))]
pub use vec::NonEmptyVec;
use core::fmt;
pub mod prelude {
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "alloc", feature = "std"))))]
#[doc(inline)]
pub use super::not_empty_vec;
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "alloc", feature = "std"))))]
#[doc(inline)]
pub use super::IteratorExt as NotEmptyIteratorExt;
#[doc(inline)]
pub use super::NonEmptySlice;
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "alloc", feature = "std"))))]
#[doc(inline)]
pub use super::NonEmptyVec;
}
#[cfg(any(feature = "alloc", feature = "std"))]
#[doc(hidden)]
#[allow(unused_imports)]
pub mod __private {
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "alloc")]
pub use alloc::vec;
#[cfg(feature = "std")]
pub use std::vec;
}
#[macro_export]
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "alloc", feature = "std"))))]
macro_rules! not_empty_vec {
() => {{
compile_error!("cannot initialize non-empty vector with zero length")
}};
($elem:expr; 0) => {{
compile_error!("cannot initialize non-empty vector with zero length");
}};
($elem:expr; 0usize) => {{
compile_error!("cannot initialize non-empty vector with zero length");
}};
($elem:expr; $n:expr) => {{
unsafe { $crate::NonEmptyVec::new_unchecked($crate::__private::vec![$elem; $n]) }
}};
($($x:expr),+ $(,)?) => {{
unsafe { $crate::NonEmptyVec::new_unchecked($crate::__private::vec![$($x),+]) }
}};
}
pub type Slice<T> = NonEmptySlice<T>;
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "alloc", feature = "std"))))]
pub type Vec<T> = NonEmptyVec<T>;
#[macro_export]
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "alloc", feature = "std"))))]
macro_rules! vec {
($($tt:tt)*) => {{
$crate::not_empty_vec!($($tt)*)
}};
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct EmptyError;
impl fmt::Display for EmptyError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("empty collection")
}
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, cfg(feature = "std"))]
impl std::error::Error for EmptyError {}