Utility library to work with tuples.

Overview

Utility library to work with tuples.

Features:

  • Test if all elements are Ok: all_ok()

    assert_eq!(
        all_ok((good(1), good(2), good(3))),
        Ok((1, 2, 3)),
    );
    assert_eq!(
        all_ok((good(1), bad(2), good(3))),
        Err((Ok(1), Err(2), Ok(3)))
    );
  • Test if all elements are Some: all_some()

    assert_eq!(
        all_some((Some(1), Some(2), Some(3))),
        Ok((1, 2, 3))
    );
    assert_eq!(
        all_some((Some(1), Option::<()>::None, Some(3))),
        Err((Some(1), None, Some(3)))
    );
  • Prepend an element to a tuple: prepend()

    assert_eq!(
        prepend(1, (2, 3, 4)),
        (1, 2, 3, 4)
    );
  • Append an element to a tuple: append()

    assert_eq!(
        append((1, 2, 3), 4),
        (1, 2, 3, 4)
    );
  • Concatenate two tuples: concat_tuples()

    assert_eq!(
        concat_tuples((1, 2), (3, 4, 5)),
        (1, 2, 3, 4, 5)
    );
  • Concatenate multiple tuples: concat_many()

    assert_eq!(
        concat_many(((), (1,), (2, 3,), (4, 5, 6))),
        (1, 2, 3, 4, 5, 6)
    );
  • Turn a reference to a tuple to a tuple of references: ref_tuple()

    assert_eq!(
        ref_tuple(&(1, 2, 3)),
        (&1, &2, &3)
    );
  • Turn a reference to a mutable tuple to a tuple of mutable references: tuple_ref_mut()

    assert_eq!(
        tuple_ref_mut(&mut (1, 2, 3)),
        (&mut 1, &mut 2, &mut 3)
    );
  • Extract the first element of a tuple: unprepend()

    assert_eq!(
        unprepend((1, 2, 3, 4)),
        (1, (2, 3, 4))
    );
  • Extract the last element of a tuple: unappend()

    assert_eq!(
        unappend((1, 2, 3, 4)),
        ((1, 2, 3), 4)
    );
  • Call a function with the tuple members as arguments: apply()

    fn add3(a: u32, b: u32, c: u32) -> u32 { a + b + c }
    
    let tpl3 = (1, 2, 3);
    assert_eq!(
        apply(&add3, tpl3),
        6
    );
  • Element-wise wrap the element of a tuple in Option: option_tuple()

    assert_eq!(
        option_tuple(Some((1, 2, 3))),
        (Some(1), Some(2), Some(3))
    );
  • Get the length of a tuple: length()

    assert_eq!(<(u8, u16, u32) as TupleLength>::LENGTH, 3);
  • Map a tuple: map_tuple()

    struct MyTupleEnum(usize);
    
    impl TupleMapper for MyTupleEnum {
        type MapElem
          = (
         usize, Type);
    
        
         fn 
         map_elem
         
          (
          &
          mut 
          self, elem: Elem) -> 
          Self::MapElem
          
            {
            
           let index 
           = 
           self.
           0;
            
           self.
           0 
           += 
           1;
            (index, elem)
        }
    }
    
    
           assert_eq!(
        
           map_tuple(
           MyTupleEnum(
           1), (
           "hello", 
           "world", 
           "!")),
        ((
           1, 
           "hello"), (
           2, 
           "world"), (
           3, 
           "!")),
    )
          
         
        

Supported tuple lengths:

By default the selected operations are implemented to tuples upto a length of 16 elements (features = ["default-len"]).

You can specify a higher limit by using feature = ["X"], where X can be 8, 16, 32, 64, 96, 128, 160, 192, 224, or 256. A higher number includes all lower numbers.

You might also like...
ᎩᎦᎨᎢ (IPA: [gigagei]) is a random quote fetching console utility. Written in Rust.
ᎩᎦᎨᎢ (IPA: [gigagei]) is a random quote fetching console utility. Written in Rust.

gigagei ᎩᎦᎨᎢ (IPA: [gigagei]) is a random quote fetching console utility. Written in Rust. Installing Use latest pre-built binary from releases Buildi

Devmode is a project management utility for developers.
Devmode is a project management utility for developers.

Dev(mode) Dev(mode) is a project management utility for developers.

A fast, multi-threaded line counting utility written in Rust.

xloc A fast, multi-threaded line counting utility written in Rust. What is xloc A drop in replacement for bash's wc -l. Your project has x lines of co

Provides utility functions to perform a graceful shutdown on an tokio-rs based service

tokio-graceful-shutdown IMPORTANT: This crate is in an early stage and not ready for production. This crate provides utility functions to perform a gr

A cli utility written in Rust that allows fetching all the labels of a project, save those as a YAML file

A cli utility written in Rust that allows fetching all the labels of a project, save those as a YAML file that you can easily edit or save as backup and apply a saved preset to new repositories.

Progmem utility for the AVR architecture

avr-progmem Progmem utilities for the AVR architectures. This crate provides unsafe utilities for working with data stored in the program memory of an

Emoji-printer - Utility to convert strings with emoji shortcodes to strings with the emoji unicode

Emoji Printer Intro Utility to convert strings with emoji shortcodes (:sushi:) to strings with the emoji unicode ( 🍣 ) Install cargo add emoji-printe

Rs.aws-login - A command line utility to simplify logging into AWS services.

aws-login A command line utility to simplify logging into AWS accounts and services. $ aws-login use ? Please select a profile to use: › ❯ dev-read

A rust-based version of the popular dnsgen python utility

ripgen A rust-based version of the popular dnsgen python utility. ripgen is split into two main parts: ripgen: A CLI utility that calls into ripgen_li

Owner
René Kijewski
René Kijewski
A lite tool to make systemd work in any container(Windows Subsystem for Linux 2, Docker, Podman, etc.)

Angea Naming from hydrangea(アジサイ) A lite tool to make systemd work in any container(Windows Subsystem for Linux 2, Docker, Podman, etc.) WSL1 is not s

いんしさくら 16 Dec 5, 2022
Easily sync your clipboard between devices. This is a work in progress app.

Clipboard Sync Description Easily sync your clipboard between devices. This is a work in progress app. Stack Frontend: React Tauri isomorphic-ws TSX,

Steveplays 2 Mar 2, 2022
cargo-lambda a Cargo subcommand to help you work with AWS Lambda

cargo-lambda cargo-lambda is a Cargo subcommand to help you work with AWS Lambda. This subcommand compiles AWS Lambda functions natively and produces

David Calavera 184 Jan 5, 2023
cargo-lambda is a Cargo subcommand to help you work with AWS Lambda.

cargo-lambda cargo-lambda is a Cargo subcommand to help you work with AWS Lambda. The new subcommand creates a basic Rust package from a well defined

null 184 Jan 5, 2023
A simple string parsing utility library for Rust, supporting no_std contexts.

strp Utility library for parsing data from an input string, or stdin if built with the std feature. Supports no_std contexts when built without the st

iqon 5 Nov 3, 2022
A Rust utility library, making easier by taking the hassle out of working. :octocat:

reddish A Rust utility library, making easier by taking the hassle out of working. Usage Add this to your Cargo.toml: [dependencies] reddish = "0.2.0"

Rogério Araújo 12 Jan 21, 2023
⏲ Situwaition is a Rust utility library that waits for conditions

⏲ situwaition situwaition runs a closure continuously, until an Ok(..) is received, or a timeout period elapses. Install cargo add situwaition

Victor Adossi ( 3 Jul 30, 2023
Batch rename utility for developers

nomino Batch rename utility for developers How to install Pre-Compiled You can download a pre-compiled executable for Linux, MacOS and Windows operati

Navid 458 Dec 27, 2022
A small utility for tracking the change in opening and closing of issues in a GitHub repo

A small utility for tracking the change in opening and closing of issues in a GitHub repo. This tool can be used to build visualizations for issue triage over time with the hope of motivating closing more issues than are opened.

Ryan Levick 12 Sep 29, 2021
mdTranslation is a utility to prepare multi-lingual Markdown documents.

mdTranslation is a utility to prepare multi-lingual Markdown documents. There's also a mdBook preprocessor called mdbook-translation for

Charles Lew 15 Dec 26, 2022