stable array collectors
| -rw-r--r-- | Cargo.toml | 9 | ||||
| -rw-r--r-- | LICENSE | 21 | ||||
| -rw-r--r-- | README.md | 10 | ||||
| -rw-r--r-- | src/lib.rs | 17 |
4 files changed, 52 insertions, 5 deletions
@@ -1,9 +1,12 @@ [package] name = "collar" -version = "0.1.0" +version = "1.0.0" edition = "2024" - -[dependencies] +authors = ["bend-n <[email protected]>"] +license = "MIT" +description = "easy array collection" +repository = "https://github.com/bend-n/collar" +keywords = ["array", "utility", "collect", "iterators"] [package.metadata.docs.rs] rustdoc-args = ["--generate-link-to-definition"] @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 bendn + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..74c1def --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# collar + +this crate provides `collect_array` and makes it easy to collect to small stack allocated arrays + +```rs +use collar::*; +let Some([ty, path, http]) = request.split(' ').collect_array_checked() else { + return; +}; +``` @@ -1,4 +1,17 @@ -pub use error::Error; +//! provides [`collect_array`](CollectArray::collect_array) and [`try_from_fn`]. +//! allowing easy allocation-free collection to an array. +//! +//! ``` +//! # /* +//! use collar::*; +//! let Some([ty, path, http]) = request.split(' ').collect_array_checked() else { +//! return; +//! }; +//! # */ +//! ``` + +use error::Error; +pub use error::Error as CollectorError; use std::{ mem::{ManuallyDrop as MD, MaybeUninit as MU, forget}, ptr::drop_in_place, @@ -46,7 +59,7 @@ pub trait CollectArray: Iterator + Sized { /// Creates an array [T; N] where each fallible (i.e [`Option`] or [`Result`]) element is begotten from [`next`](Iterator::next). /// Unlike [`collect_array`](CollectArray::collect_array), where the element creation can't fail, this version will return an error if any element creation was unsuccessful (returned [`Err`] or [`None`]). - /// In the case where the iterator ran out of elements, this returns a [`CollectorError::Amount`] + /// In the case where the iterator ran out of elements, this returns a [`CollectorError`] containing the count. /// /// The return type of this function depends on the [`Item`](Iterator::Item) of this [`Iterator`]. /// If you return `Result<T, E>` from the closure, you'll get a `Result<[T; N], CollectorError<E>>`. |