From 34ed1b98f6f6acbc54cdf30b7f20af6acdd34c63 Mon Sep 17 00:00:00 2001 From: Avril Date: Mon, 5 Dec 2022 21:59:49 +0000 Subject: [PATCH] Reowkred into a namespace structure that splits different utils into seperate packages with the prefix `flan-utils-`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortune for flan-utils-rs's current commit: Future curse − 末凶 --- Cargo.toml | 27 ++++---- flan-utils-iter/Cargo.toml | 12 ++++ flan-utils-iter/src/ext.rs | 34 ++++++++++ flan-utils-iter/src/lib.rs | 13 ++++ flan-utils-iter/src/tuple.rs | 79 ++++++++++++++++++++++++ flan-utils-macros/Cargo.toml | 19 ++++++ {src => flan-utils-macros/src}/lib.rs | 0 {src => flan-utils-macros/src}/macros.rs | 0 8 files changed, 168 insertions(+), 16 deletions(-) create mode 100644 flan-utils-iter/Cargo.toml create mode 100644 flan-utils-iter/src/ext.rs create mode 100644 flan-utils-iter/src/lib.rs create mode 100644 flan-utils-iter/src/tuple.rs create mode 100644 flan-utils-macros/Cargo.toml rename {src => flan-utils-macros/src}/lib.rs (100%) rename {src => flan-utils-macros/src}/macros.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 63536c8..8221a98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,19 +1,14 @@ -[package] -name = "flan-utils" -version = "0.1.0" -authors = ["Avril "] -edition = "2018" -license = "MIT" +[workspace] +members = [ + "flan-utils-macros", + "flan-utils-iter", +] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[profile.release] +opt-level = 3 +lto = "fat" +codegen-units = 1 +panic = "unwind" +strip=true -[features] -default = ["macros"] -# #![no_std] support -no_std = [] - -# Enable the macros section -macros = [] - -[dependencies] diff --git a/flan-utils-iter/Cargo.toml b/flan-utils-iter/Cargo.toml new file mode 100644 index 0000000..f7c542b --- /dev/null +++ b/flan-utils-iter/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "flan-utils-iter" +version = "0.1.0" +authors = ["Avril "] +edition = "2018" +license = "MIT" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[features] + +[dependencies] diff --git a/flan-utils-iter/src/ext.rs b/flan-utils-iter/src/ext.rs new file mode 100644 index 0000000..40e7278 --- /dev/null +++ b/flan-utils-iter/src/ext.rs @@ -0,0 +1,34 @@ +//! Extensions +use super::*; +use std::{ + iter::{self, Fuse,} +}; +pub trait TaekTwoExt: Iterator +{ + fn take_two(self) -> TakeTwo; +} + +#[derive(Debug, Clone)] +pub struct TakeTwo(I); + +impl + ?Sized> Iterator for TakeTwo +{ + type Item = (T, Option); + #[inline] + fn next(&mut self) -> Option + { + let first = self.0.next()?; + Some((first, self.0.next())) + } +} + +impl TaekTwoExt for I +where I: Iterator + Sized +{ + #[inline] + fn take_two(self) -> TakeTwo { + TakeTwo(self) + } +} + +//TODO: XXX: Copy all other iterator `ext` traits like `Collection: Extend, U: Into` (e.g. `String` with `char`) joining and such from older projects diff --git a/flan-utils-iter/src/lib.rs b/flan-utils-iter/src/lib.rs new file mode 100644 index 0000000..579bfad --- /dev/null +++ b/flan-utils-iter/src/lib.rs @@ -0,0 +1,13 @@ +//! Collection of iterator (and tuple) tools +mod ext; +pub mod tuple; +pub use crate::{ + ext::{ + TaekTwoExt, + TakeTwo, + }, + tuple::{ + UntupleTwoExt, + TryUntupleTwoExt, + }, +}; diff --git a/flan-utils-iter/src/tuple.rs b/flan-utils-iter/src/tuple.rs new file mode 100644 index 0000000..44f6e7a --- /dev/null +++ b/flan-utils-iter/src/tuple.rs @@ -0,0 +1,79 @@ +//! Tuple traits +use super::*; + +pub trait TryUntupleTwoExt: Sized +{ + type Wrapper; + fn both(self) -> Self::Wrapper<(T, U)>; +} + +impl TryUntupleTwoExt for (T, Option) +{ + type Wrapper = Option; + #[inline] + fn both(self) -> Self::Wrapper<(T, U)> { + match self { + (first, Some(second)) => Some((first, second)), + _ => None, + } + } +} + +impl TryUntupleTwoExt for (Option, U) +{ + type Wrapper = Option; + #[inline] + fn both(self) -> Self::Wrapper<(T, U)> { + match self { + (Some(first), second) => Some((first, second)), + _ => None, + } + } +} + +impl TryUntupleTwoExt for (Option, Option) +{ + type Wrapper = Option; + #[inline] + fn both(self) -> Self::Wrapper<(T, U)> { + match self { + (Some(first), Some(second)) => Some((first, second)), + _ => None, + } + } +} + +pub trait UntupleTwoExt: Sized +{ + type Unwrapped; + + fn untuple(self) -> Self::Unwrapped; +} + +impl UntupleTwoExt for (T, (U, V)) +{ + type Unwrapped = (A,B,C); + #[inline] + fn untuple(self) -> Self::Unwrapped { + (self.0, self.1.0, self.1.1) + } +} + +impl UntupleTwoExt for (T, (U,)) +{ + type Unwrapped = (A,B); + #[inline] + fn untuple(self) -> Self::Unwrapped { + (self.0, self.1.0) + } +} + +impl UntupleTwoExt for (T,) +{ + type Unwrapped = A; + #[inline] + fn untuple(self) -> Self::Unwrapped { + self.0 + } +} + diff --git a/flan-utils-macros/Cargo.toml b/flan-utils-macros/Cargo.toml new file mode 100644 index 0000000..01b4e6e --- /dev/null +++ b/flan-utils-macros/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "flan-utils-macros" +version = "0.1.0" +authors = ["Avril "] +edition = "2018" +license = "MIT" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[features] +default = ["macros"] + +# #![no_std] support +no_std = [] + +# Enable the macros section +macros = [] + +[dependencies] diff --git a/src/lib.rs b/flan-utils-macros/src/lib.rs similarity index 100% rename from src/lib.rs rename to flan-utils-macros/src/lib.rs diff --git a/src/macros.rs b/flan-utils-macros/src/macros.rs similarity index 100% rename from src/macros.rs rename to flan-utils-macros/src/macros.rs