From 95981e00ff45dae4f87c2ecb4c4fecde6e437fda Mon Sep 17 00:00:00 2001 From: Sean Smith Date: Sat, 21 Dec 2024 09:45:35 -0600 Subject: [PATCH] iterutil crate --- Cargo.lock | 5 +++++ crates/iterutil/Cargo.toml | 6 ++++++ crates/iterutil/src/exact_size.rs | 25 ++++++++++++++++++++++ crates/iterutil/src/lib.rs | 1 + crates/rayexec_execution/Cargo.toml | 1 + crates/rayexec_execution/src/arrays/mod.rs | 1 + crates/rayexec_execution/src/lib.rs | 1 + 7 files changed, 40 insertions(+) create mode 100644 crates/iterutil/Cargo.toml create mode 100644 crates/iterutil/src/exact_size.rs create mode 100644 crates/iterutil/src/lib.rs create mode 100644 crates/rayexec_execution/src/arrays/mod.rs diff --git a/Cargo.lock b/Cargo.lock index ee9d2aca1..e51d89c02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1391,6 +1391,10 @@ dependencies = [ "either", ] +[[package]] +name = "iterutil" +version = "0.0.93" + [[package]] name = "itoa" version = "1.0.10" @@ -2270,6 +2274,7 @@ dependencies = [ "half", "hashbrown 0.14.5", "indexmap", + "iterutil", "num-traits", "num_cpus", "once_cell", diff --git a/crates/iterutil/Cargo.toml b/crates/iterutil/Cargo.toml new file mode 100644 index 000000000..39c919663 --- /dev/null +++ b/crates/iterutil/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "iterutil" +version.workspace = true +edition.workspace = true + +[dependencies] diff --git a/crates/iterutil/src/exact_size.rs b/crates/iterutil/src/exact_size.rs new file mode 100644 index 000000000..1385f1c37 --- /dev/null +++ b/crates/iterutil/src/exact_size.rs @@ -0,0 +1,25 @@ +/// Similar to `IntoIterator`, but for an iterator with an exact size. +pub trait IntoExactSizeIterator { + type Item; + type IntoIter: ExactSizeIterator; + + /// Converts self into the `ExactSizeIteror`. + fn into_iter(self) -> Self::IntoIter; +} + +impl IntoExactSizeIterator for I +where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, +{ + type Item = I::Item; + type IntoIter = I::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.into_iter() + } +} + +pub trait FromExactSizeIterator: Sized { + fn from_iter>(iter: T) -> Self; +} diff --git a/crates/iterutil/src/lib.rs b/crates/iterutil/src/lib.rs new file mode 100644 index 000000000..b44919ad5 --- /dev/null +++ b/crates/iterutil/src/lib.rs @@ -0,0 +1 @@ +pub mod exact_size; diff --git a/crates/rayexec_execution/Cargo.toml b/crates/rayexec_execution/Cargo.toml index fe854c462..2f05d40f3 100644 --- a/crates/rayexec_execution/Cargo.toml +++ b/crates/rayexec_execution/Cargo.toml @@ -10,6 +10,7 @@ rayexec_parser = { path = "../rayexec_parser" } rayexec_bullet = { path = "../rayexec_bullet" } rayexec_io = { path = "../rayexec_io" } fmtutil = { path = "../fmtutil" } +iterutil = { path = "../iterutil" } # stackutil = { path = "../stackutil" } TODO: psm hash issues when compiling to wasm on macos ahash = { workspace = true } diff --git a/crates/rayexec_execution/src/arrays/mod.rs b/crates/rayexec_execution/src/arrays/mod.rs new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/crates/rayexec_execution/src/arrays/mod.rs @@ -0,0 +1 @@ + diff --git a/crates/rayexec_execution/src/lib.rs b/crates/rayexec_execution/src/lib.rs index 36d966315..5c067bc7c 100644 --- a/crates/rayexec_execution/src/lib.rs +++ b/crates/rayexec_execution/src/lib.rs @@ -1,3 +1,4 @@ +pub mod arrays; pub mod config; pub mod database; pub mod datasource;