clockwork_tuples/lib.rs
1#![deny(missing_docs)]
2
3//! Tuple-oriented type-level utilities.
4//!
5//! This crate provides traits and helpers for reasoning about and
6//! manipulating tuple types at the type level. It is intended for
7//! library consumers that need compile-time guarantees over tuple
8//! structure, ordering, and containment.
9//!
10//! # Guarantees
11//!
12//! - All public traits define structural properties of tuple types.
13//! - No runtime allocation is performed by this crate.
14//! - APIs are pure with respect to observable runtime state.
15//!
16//! # Examples
17//! ```
18//! use clockwork_tuples::traits::{
19//! as_cons_tuple::AsConsTuple,
20//! as_ref_tuple::AsRefTuple,
21//! has::Has,
22//! };
23//!
24//! fn foo() {
25//! let tuple = ("alpha", 7u8, true);
26//!
27//! // Convert the tuple into a cons-style representation for structural recursion.
28//! let cons = tuple.to_cons_tuple();
29//! assert_eq!(cons.0, "alpha");
30//! assert_eq!(cons.1.0, 7u8);
31//! assert!(cons.1.1.0);
32//!
33//! // Navigate to the boolean
34//! let val: bool = tuple.get();
35//! assert!(val);
36//! }
37//!
38//! fn borrow_refs() {
39//! let mut borrowable = ("bravo".to_string(), 3u8, false);
40//!
41//! // Borrow shared refs without moving ownership.
42//! {
43//! let (label, count, flag) = borrowable.as_refs();
44//! assert_eq!(label.as_str(), "bravo");
45//! assert_eq!(*count, 3u8);
46//! assert!(!*flag);
47//! }
48//!
49//! // Borrow mutable refs to update individual elements in place.
50//! {
51//! let (label_mut, count_mut, flag_mut) = borrowable.as_muts();
52//! label_mut.push_str("-borrowed");
53//! *count_mut += 1;
54//! *flag_mut = true;
55//! }
56//!
57//! assert_eq!(borrowable.0, "bravo-borrowed");
58//! assert_eq!(borrowable.1, 4u8);
59//! assert!(borrowable.2);
60//! }
61//! ```
62
63pub mod index;
64pub(crate) mod macros;
65pub mod traits;