#hlist #coproduct #generic #labelled-generic

no-std frunk_core

Frunk core provides developers with HList, Coproduct, LabelledGeneric and Generic

36 releases

0.4.4 Jun 14, 2025
0.4.3 Aug 31, 2024
0.4.2 Jun 17, 2023
0.4.1 Nov 3, 2022
0.0.11 Mar 22, 2017

#1 in #coproduct

Download history 55484/week @ 2025-10-21 64253/week @ 2025-10-28 56133/week @ 2025-11-04 43178/week @ 2025-11-11 60947/week @ 2025-11-18 47927/week @ 2025-11-25 53082/week @ 2025-12-02 58227/week @ 2025-12-09 56663/week @ 2025-12-16 35302/week @ 2025-12-23 34245/week @ 2025-12-30 53374/week @ 2026-01-06 62333/week @ 2026-01-13 85312/week @ 2026-01-20 92756/week @ 2026-01-27 99128/week @ 2026-02-03

349,154 downloads per month
Used in 345 crates (43 directly)

MIT license

200KB
3K SLoC

Frunk Core

This library forms the core of Frunk. It should ideally be minimalistic, containing only the fundamental building blocks of generic programming.

Examples


let h = hlist![1, false, 42f32];
let folded = h.foldr(hlist![|acc, i| i + acc,
    |acc, _| if acc > 42f32 { 9000 } else { 0 },
    |acc, f| f + acc],
    1f32);
assert_eq!(folded, 9001);

// Reverse
let h1 = hlist![true, "hi"];
assert_eq!(h1.into_reverse(), hlist!["hi", true]);

// foldr (foldl also available)
let h2 = hlist![1, false, 42f32];
let folded = h2.foldr(
            hlist![|acc, i| i + acc,
                   |acc, _| if acc > 42f32 { 9000 } else { 0 },
                   |acc, f| f + acc],
            1f32
    );
assert_eq!(folded, 9001);

// Mapping over an HList
let h3 = hlist![9000, "joe", 41f32];
let mapped = h3.to_ref().map(hlist![|&n| n + 1,
                              |&s| s,
                              |&f| f + 1f32]);
assert_eq!(mapped, hlist![9001, "joe", 42f32]);

// Plucking a value out by type
let h4 = hlist![1, "hello", true, 42f32];
let (t, remainder): (bool, _) = h4.pluck();
assert!(t);
assert_eq!(remainder, hlist![1, "hello", 42f32]);

// Resculpting an HList
let h5 = hlist![9000, "joe", 41f32, true];
let (reshaped, remainder2): (HList![f32, i32, &str], _) = h5.sculpt();
assert_eq!(reshaped, hlist![41f32, 9000, "joe"]);
assert_eq!(remainder2, hlist![true]);

Links:

  1. Source on Github
  2. Crates.io page

Dependencies

~155KB