An open API service indexing awesome lists of open source software.

https://github.com/nwtgck/tuple-map-rust

.map() operation for tuples in Rust
https://github.com/nwtgck/tuple-map-rust

macro map rust tuple

Last synced: about 1 year ago
JSON representation

.map() operation for tuples in Rust

Awesome Lists containing this project

README

          

# tuple-map
![Rust](https://github.com/nwtgck/tuple-map-rust/workflows/Rust/badge.svg?branch=develop)

.map() operation for tuples in Rust

## Install

```toml
# Cargo.toml

[dependencies]
tuple-map = { git = "https://github.com/nwtgck/tuple-map-rust.git" }
```

## Examples

Here are examples.

```rust
use tuple_map::tuple_map;

let a = tuple_map!((10, "hello", 1.23), x, {
format!("{:?}", x)
});
assert_eq!(a, ("10".to_string(), "\"hello\"".to_string(), "1.23".to_string()));
```

```rust
use tuple_map::tuple_map;

fn f1(vec: &mut Vec) -> u32 {
vec.push(1);
10
}

fn f2(vec: &mut Vec) -> &'static str {
vec.push(2);
"hello"
}

fn f3(vec: &mut Vec) -> f32 {
vec.push(3);
1.2
}

let mut vec: Vec = Vec::new();
let a = tuple_map!((f1, f2, f3), f, {
f(&mut vec)
});
assert_eq!(a, (10, "hello", 1.2));
assert_eq!(vec, vec![1, 2, 3]);
```