1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! # Overview
//!
//! This library exposes [`decompose!`], a macro to decompose tuples into tuples containing a
//! subset of their values.
//!
//! ```
//! use compost::decompose;
//!
//! let mut cx = (&1u32, &mut 2i32, 'c', "d", Box::new(5u8), 6i8);
//!
//! fn function_taking_subset(cx: (&u32, &i32, &mut u8)) {
//!     dbg!(cx);
//! }
//!
//! function_taking_subset(decompose!(cx));
//!
//! decompose!(cx => cx_rest & {
//!     value_1: &str,
//!     value_2: &mut char,
//! });
//!
//! dbg!((value_1, value_2));
//!
//! decompose!(cx_rest => { value_3: &u32, value_4: &mut i8 });
//!
//! dbg!((value_3, value_4));
//!
//! function_taking_subset(decompose!(cx_rest));
//! function_taking_subset(decompose!(cx));
//! ```
//!
//! See [`decompose!`]'s documentation for more details on the precise semantics and
//! limitations of the macro.
//!
//! ## Features
//!
//! Yes, this library...
//!
//! - Supports reborrowing (i.e. `decompose!` does not consume its input. Once you're done
//!    with the borrow, you can reuse the original tuple).
//! - Produces (admittedly pretty ugly) errors at compile time if the tuple cannot be decomposed.
//! - Supports borrowing mutable, immutable, owned, and smart-pointer wrapped (so long as they implement
//!   [`Borrow`](core::borrow::Borrow)) components.
//! - Supports borrowing generic elements without failing spuriously on monomorphization.
//! - Relies on type inference rather than `TypeId`, allowing the macro to operate on non-`'static` types.
//! - Supports `no_std` environments.
//! - Has zero runtime dependencies.
//!

#![no_std]

#[macro_use]
#[path = "generated/decompose.rs"]
mod decompose;

#[doc(hidden)]
pub mod macro_internal {
    pub use super::decompose::*;
    pub use core::{
        convert::identity,
        option::Option::{None, Some},
    };
}