stable array collectors
no-std
| -rw-r--r-- | Cargo.toml | 3 | ||||
| -rw-r--r-- | src/error.rs | 12 | ||||
| -rw-r--r-- | src/lib.rs | 13 |
3 files changed, 15 insertions, 13 deletions
@@ -1,12 +1,13 @@ [package] name = "collar" -version = "1.0.0" +version = "1.0.1" edition = "2024" authors = ["bend-n <[email protected]>"] license = "MIT" description = "easy array collection" repository = "https://github.com/bend-n/collar" keywords = ["array", "utility", "collect", "iterators"] +categories = ["no-std", "algorithms", "rust-patterns", "no-std::no-alloc"] [package.metadata.docs.rs] rustdoc-args = ["--generate-link-to-definition"] diff --git a/src/error.rs b/src/error.rs index 2f4e3c4..027c8a5 100644 --- a/src/error.rs +++ b/src/error.rs @@ -13,8 +13,8 @@ impl<const N: usize, const O: usize, E: PartialEq> PartialEq<Error<O, E>> for Er } } -impl<const N: usize, E: std::fmt::Display> std::fmt::Display for Error<N, E> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl<const N: usize, E: core::fmt::Display> core::fmt::Display for Error<N, E> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match (&self.error, &self.at) { (Some(x), at) => write!(f, "{x} @ {at} of {N}"), (None, at) => write!( @@ -25,8 +25,8 @@ impl<const N: usize, E: std::fmt::Display> std::fmt::Display for Error<N, E> { } } -impl<const N: usize, E: std::fmt::Debug> std::fmt::Debug for Error<N, E> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl<const N: usize, E: core::fmt::Debug> core::fmt::Debug for Error<N, E> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match (&self.error, &self.at) { (Some(x), at) => write!(f, "{x:?} @ {at} of {N}"), (None, at) => write!(f, "Size(wanted {N}, had {at})"), @@ -34,8 +34,8 @@ impl<const N: usize, E: std::fmt::Debug> std::fmt::Debug for Error<N, E> { } } -impl<const N: usize, E: std::error::Error + 'static> std::error::Error for Error<N, E> { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +impl<const N: usize, E: core::error::Error + 'static> core::error::Error for Error<N, E> { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { Some(self.error.as_ref()?) } } @@ -1,5 +1,6 @@ +#![no_std] //! provides [`collect_array`](CollectArray::collect_array) and [`try_from_fn`]. -//! allowing easy allocation-free collection to an array. +//! allowing easy vec-free collection to an array. //! //! ``` //! # /* @@ -10,12 +11,12 @@ //! # */ //! ``` -use error::Error; -pub use error::Error as CollectorError; -use std::{ +use core::{ mem::{ManuallyDrop as MD, MaybeUninit as MU, forget}, ptr::drop_in_place, }; +use error::Error; +pub use error::Error as CollectorError; mod error; mod maybe; use maybe::Maybe; @@ -102,7 +103,7 @@ pub trait CollectArray: Iterator + Sized { /// ) /// ``` fn items<const N: usize>(&mut self) -> [Option<Self::Item>; N] { - std::array::from_fn(|_| self.next()) + from_fn(|_| self.next()) } } impl<I: Iterator> CollectArray for I {} @@ -185,4 +186,4 @@ pub fn try_from_fn<R: Maybe, const N: usize>( } #[doc(no_inline)] -pub use std::array::from_fn; +pub use core::array::from_fn; |