Tuple Set: Operate on Rust tuples by type, not position
github.com·11h·
Discuss: r/rust
Flag this post

Tuple Set

Ergonomic utilities for working with stable Rust tuples by unique type, not by position.

When implementing generic traits, you often care about a type inside a tuple rather than its position. The location may differ across tuple types and may not even be knowable. Tuple Set allows you to operate on tuple values by type when that type appears exactly once.

  • Fully no_std compatible
  • Zero dependencies
  • Works with tuples up to 64 elements (feature-gating can extend this)
  • Supports duplicated types in the same tuple as long as the target type is unique

Example

use tuple_set::TupleSet;

let mut tuple = (42i32, "hello", None::<&str>, "world", 3.14f64);

// Replace the i32 by type
assert!(tuple.set(100i32).is_none());
assert_eq!(tuple.0, 100);

// Make...

Similar Posts

Loading similar posts...