Crates.io | tupl |
lib.rs | tupl |
version | 0.4.0 |
source | src |
created_at | 2023-04-03 21:32:27.335751 |
updated_at | 2023-04-07 15:59:51.984517 |
description | Perform generic operations on tuples. |
homepage | |
repository | https://github.com/Dragoteryx/tupl |
max_upload_size | |
id | 829523 |
size | 12,089 |
A #![no_std]
crate for handling Rust tuples using traits.
This is accomplished via 3 traits:
use tupl::{GrowableTuple, NonEmptyTuple};
let mut tuple = (1, 2);
// access the first & last elements of a tuple
*tuple.head_mut() = *tuple.head() + 1;
*tuple.tail_mut() = *tuple.tail() + 1;
assert_eq!(tuple, (2, 3));
// append an element to a tuple
let tuple = tuple.append(4);
assert_eq!(tuple, (2, 3, 4));
// prepend an element to a tuple
let tuple = tuple.prepend(1);
assert_eq!(tuple, (1, 2, 3, 4));
// truncate the first element of a tuple
let (head, tuple) = tuple.truncate_head();
assert_eq!((head, tuple), (1, (2, 3, 4)));
// truncate the last element of a tuple
let (tuple, tail) = tuple.truncate_tail();
assert_eq!((tuple, tail), ((2, 3), 4));