frunk_core/
lib.rs

1#![no_std]
2#![doc(html_playground_url = "https://play.rust-lang.org/")]
3//! Frunk Core
4//!
5//! This library forms the core of Frunk. It should ideally be minimalistic,
6//! containing only the fundamental building blocks of generic programming.
7//!
8//! # Examples
9//!
10//! ```
11//! # use frunk_core::hlist::*;
12//! # use frunk_core::{hlist, HList};
13//! # fn main() {
14//!
15//! let h = hlist![1, false, 42f32];
16//! let folded = h.foldr(hlist![|acc, i| i + acc,
17//!     |acc, _| if acc > 42f32 { 9000 } else { 0 },
18//!     |acc, f| f + acc],
19//!     1f32);
20//! assert_eq!(folded, 9001);
21//!
22//! // Reverse
23//! let h1 = hlist![true, "hi"];
24//! assert_eq!(h1.into_reverse(), hlist!["hi", true]);
25//!
26//! // foldr (foldl also available)
27//! let h2 = hlist![1, false, 42f32];
28//! let folded = h2.foldr(
29//!             hlist![|acc, i| i + acc,
30//!                    |acc, _| if acc > 42f32 { 9000 } else { 0 },
31//!                    |acc, f| f + acc],
32//!             1f32
33//!     );
34//! assert_eq!(folded, 9001);
35//!
36//! // Mapping over an HList
37//! let h3 = hlist![9000, "joe", 41f32];
38//! let mapped = h3.to_ref().map(hlist![|&n| n + 1,
39//!                               |&s| s,
40//!                               |&f| f + 1f32]);
41//! assert_eq!(mapped, hlist![9001, "joe", 42f32]);
42//!
43//! // Plucking a value out by type
44//! let h4 = hlist![1, "hello", true, 42f32];
45//! let (t, remainder): (bool, _) = h4.pluck();
46//! assert!(t);
47//! assert_eq!(remainder, hlist![1, "hello", 42f32]);
48//!
49//! // Resculpting an HList
50//! let h5 = hlist![9000, "joe", 41f32, true];
51//! let (reshaped, remainder2): (HList![f32, i32, &str], _) = h5.sculpt();
52//! assert_eq!(reshaped, hlist![41f32, 9000, "joe"]);
53//! assert_eq!(remainder2, hlist![true]);
54//! # }
55//! ```
56//!
57//! Links:
58//!   1. [Source on Github](https://github.com/lloydmeta/frunk)
59//!   2. [Crates.io page](https://crates.io/crates/frunk)
60
61#[cfg(test)]
62extern crate std;
63
64#[cfg(feature = "alloc")]
65extern crate alloc;
66
67#[macro_use]
68mod macros;
69
70pub mod coproduct;
71pub mod generic;
72pub mod hlist;
73pub mod indices;
74pub mod labelled;
75pub mod path;
76pub mod traits;
77mod tuples;
78
79#[cfg(test)]
80mod test_structs;