stable array collectors
add metadata and more docs
bendn 2025-02-08
parent 4b9914c · commit 2a80d83
-rw-r--r--Cargo.toml9
-rw-r--r--LICENSE21
-rw-r--r--README.md10
-rw-r--r--src/lib.rs17
4 files changed, 52 insertions, 5 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 3a1799b..a759c0e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"]
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..bf3f588
--- /dev/null
+++ b/LICENSE
@@ -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;
+};
+```
diff --git a/src/lib.rs b/src/lib.rs
index 7fb0186..f2c50e1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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>>`.