Skip to main content

tuple_projections/
lib.rs

1#![no_std]
2
3//! # Overview
4#![doc = include_utils::include_md!("README.md:description")]
5//!
6//! # Tuple projections
7#![doc = include_utils::include_md!("README.md:tuple_projection_example")]
8//!
9//! # Product types
10#![doc = include_utils::include_md!("README.md:product_example")]
11//!
12//! # FoundationDB-style ordered keys
13#![doc = include_utils::include_md!("README.md:fdb_example")]
14
15extern crate self as tuple_projections;
16
17pub use tuple_projections_derive::{TupleProjection, impl_left_projections};
18
19/// Relates a tuple prefix to the complete tuple it prefixes.
20pub trait LeftProjectionOf<T> {
21    /// The suffix remaining after removing the prefix from `T`.
22    type Remainder;
23}
24
25/// Converts a product type to and from its canonical tuple representation.
26///
27/// **Field declaration order is semantic.** For types using
28/// `#[derive(TupleProjection)]`, it defines positional fields and projections;
29/// when field types differ, reordering also changes the associated tuple type.
30pub trait TupleRepr: Sized {
31    /// The ordered tuple of field types represented by `Self`.
32    type Tuple;
33
34    /// Converts this product value into its tuple representation.
35    fn into_tuple(self) -> Self::Tuple;
36
37    /// Converts a tuple representation into this product value.
38    fn from_tuple(tuple: Self::Tuple) -> Self;
39}
40
41impl_left_projections!(32);