https://github.com/andogq/tuple-traits
Additional tuple traits to enable ergonomic types.
https://github.com/andogq/tuple-traits
blazingly-fast cons ergonomic rust trait tuples types typestate
Last synced: 29 days ago
JSON representation
Additional tuple traits to enable ergonomic types.
- Host: GitHub
- URL: https://github.com/andogq/tuple-traits
- Owner: andogq
- License: mit
- Created: 2024-11-11T09:01:41.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-11-11T10:02:13.000Z (7 months ago)
- Last Synced: 2025-03-28T16:18:14.955Z (2 months ago)
- Topics: blazingly-fast, cons, ergonomic, rust, trait, tuples, types, typestate
- Language: Rust
- Homepage: https://docs.rs/tuple-traits/latest
- Size: 13.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Traits
## [`Append`](https://docs.rs/tuple-traits/latest/tuple-traits/trait.Append.html)
Append a type to a tuple.
```rust
static_assertions::assert_type_eq_all!(
<(usize, char) as tuple_traits::Append>::Append,
(usize, char, bool)
);
```## [`Cons`](https://docs.rs/tuple-traits/latest/tuple-traits/trait.Cons.html)
Represent a tuple as a cons (*ish*) value, with the first value on the left, and the rest of the
tuple on the right.```rust
static_assertions::assert_impl_all!(
(usize, usize, usize): tuple_traits::Cons
);
```## [`Contains`](https://docs.rs/tuple-traits/latest/tuple-traits/trait.Contains.html)
A trait that will only be implement for a given target if it is present within a given type.
```rust
struct A;
struct B;
struct C;fn requires_c(value: T)
where
T: tuple_traits::Contains
{
}// Works!
requires_c((A, B, C));// Compiler error: `C` does not appear within `(A, B)`
// requires_c((A, B));
```# Example
Check out [`./examples/buffer-flags.rs`](./examples/buffer-flags.rs) for a full example!