Reowkred into a namespace structure that splits different utils into seperate packages with the prefix `flan-utils-`.
Fortune for flan-utils-rs's current commit: Future curse − 末凶master
parent
432653398e
commit
34ed1b98f6
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "flan-utils-iter"
|
||||
version = "0.1.0"
|
||||
authors = ["Avril <flanchan@cumallover.me>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,34 @@
|
||||
//! Extensions
|
||||
use super::*;
|
||||
use std::{
|
||||
iter::{self, Fuse,}
|
||||
};
|
||||
pub trait TaekTwoExt: Iterator
|
||||
{
|
||||
fn take_two(self) -> TakeTwo<Self>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TakeTwo<I: ?Sized + Iterator>(I);
|
||||
|
||||
impl<T, I: Iterator<Item=T> + ?Sized> Iterator for TakeTwo<I>
|
||||
{
|
||||
type Item = (T, Option<T>);
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<Self::Item>
|
||||
{
|
||||
let first = self.0.next()?;
|
||||
Some((first, self.0.next()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Iterator> TaekTwoExt for I
|
||||
where I: Iterator + Sized
|
||||
{
|
||||
#[inline]
|
||||
fn take_two(self) -> TakeTwo<Self> {
|
||||
TakeTwo(self)
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: XXX: Copy all other iterator `ext` traits like `Collection: Extend<T>, U: Into<T>` (e.g. `String` with `char`) joining and such from older projects
|
@ -0,0 +1,13 @@
|
||||
//! Collection of iterator (and tuple) tools
|
||||
mod ext;
|
||||
pub mod tuple;
|
||||
pub use crate::{
|
||||
ext::{
|
||||
TaekTwoExt,
|
||||
TakeTwo,
|
||||
},
|
||||
tuple::{
|
||||
UntupleTwoExt,
|
||||
TryUntupleTwoExt,
|
||||
},
|
||||
};
|
@ -0,0 +1,79 @@
|
||||
//! Tuple traits
|
||||
use super::*;
|
||||
|
||||
pub trait TryUntupleTwoExt<T,U>: Sized
|
||||
{
|
||||
type Wrapper<S>;
|
||||
fn both(self) -> Self::Wrapper<(T, U)>;
|
||||
}
|
||||
|
||||
impl<T, U> TryUntupleTwoExt<T, U> for (T, Option<U>)
|
||||
{
|
||||
type Wrapper<S> = Option<S>;
|
||||
#[inline]
|
||||
fn both(self) -> Self::Wrapper<(T, U)> {
|
||||
match self {
|
||||
(first, Some(second)) => Some((first, second)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, U> TryUntupleTwoExt<T, U> for (Option<T>, U)
|
||||
{
|
||||
type Wrapper<S> = Option<S>;
|
||||
#[inline]
|
||||
fn both(self) -> Self::Wrapper<(T, U)> {
|
||||
match self {
|
||||
(Some(first), second) => Some((first, second)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, U> TryUntupleTwoExt<T, U> for (Option<T>, Option<U>)
|
||||
{
|
||||
type Wrapper<S> = Option<S>;
|
||||
#[inline]
|
||||
fn both(self) -> Self::Wrapper<(T, U)> {
|
||||
match self {
|
||||
(Some(first), Some(second)) => Some((first, second)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait UntupleTwoExt<T,U,V>: Sized
|
||||
{
|
||||
type Unwrapped<A,B,C>;
|
||||
|
||||
fn untuple(self) -> Self::Unwrapped<T,U,V>;
|
||||
}
|
||||
|
||||
impl<T, U, V> UntupleTwoExt<T,U,V> for (T, (U, V))
|
||||
{
|
||||
type Unwrapped<A,B,C> = (A,B,C);
|
||||
#[inline]
|
||||
fn untuple(self) -> Self::Unwrapped<T,U,V> {
|
||||
(self.0, self.1.0, self.1.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, U> UntupleTwoExt<T,U,()> for (T, (U,))
|
||||
{
|
||||
type Unwrapped<A,B,C> = (A,B);
|
||||
#[inline]
|
||||
fn untuple(self) -> Self::Unwrapped<T,U,()> {
|
||||
(self.0, self.1.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> UntupleTwoExt<T,(),()> for (T,)
|
||||
{
|
||||
type Unwrapped<A,B,C> = A;
|
||||
#[inline]
|
||||
fn untuple(self) -> Self::Unwrapped<T,(),()> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "flan-utils-macros"
|
||||
version = "0.1.0"
|
||||
authors = ["Avril <flanchan@cumallover.me>"]
|
||||
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]
|
Loading…
Reference in new issue