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
- Host: GitHub
- URL: https://github.com/nwtgck/tuple-map-rust
- Owner: nwtgck
- License: mit
- Created: 2020-05-18T10:29:14.000Z (almost 6 years ago)
- Default Branch: develop
- Last Pushed: 2020-05-18T10:58:21.000Z (almost 6 years ago)
- Last Synced: 2025-02-06T13:29:58.833Z (about 1 year ago)
- Topics: macro, map, rust, tuple
- Language: Rust
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tuple-map

.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]);
```