pl-hlist

Crates.iopl-hlist
lib.rspl-hlist
version1.0.1
sourcesrc
created_at2019-09-13 19:27:06.454926
updated_at2020-06-28 21:26:30.088993
descriptionProvides support for heterogeneous lists (known as `HList`s), which are functional, tuple-like, strongly-typed data structures that can contain elements of differing types.
homepagehttps://github.com/plausiblelabs/hlist-rs
repositoryhttps://github.com/plausiblelabs/hlist-rs
max_upload_size
id164635
size10,779
Chris Campbell (chrispcampbell)

documentation

README

pl-hlist

Build Status Crates.io Docs.rs MIT licensed

This Rust library provides support for heterogeneous lists (known as HLists). An HList is a functional, tuple-like, strongly-typed data structure that can contain elements of differing types.

There are three layers in this library:

  • A basic HList data structure consisting of HCons and HNil types.
  • An hlist! macro for constructing an HList from a series of elements.
  • An HListSupport plugin/attribute that, when declared for a struct, allows for easy conversion of struct instances to/from an HList representation.

See the next section for more details on usage of these layers.

Usage

Add a dependency to your Cargo.toml:

[dependencies]
pl-hlist = "1.0"

Then, in your crate:

use pl_hlist::*;

An HList can be constructed manually as follows:

let x: HCons<u8, HCons<u32, HNil>> = HCons(1u8, HCons(666u32, HNil));

The hlist! macro provides a convenient shorthand for constructing an HList:

let x: HCons<u8, HCons<u32, HNil>> = hlist!(1u8, 666u32);

The custom HListSupport derive attribute can be applied to a struct declaration to automatically implement support for converting that struct to/from an HList representation:

#[derive(HListSupport)]
struct TestStruct {
    foo: u8,
    bar: u32
}

let hlist0 = hlist!(1u8, 666u32);
let s = TestStruct::from_hlist(hlist0);
assert_eq!(s.foo, 1u8);
assert_eq!(s.bar, 666u32);
let hlist1 = s.into_hlist();
assert_eq!(hlist0, hlist1);

License

pl-hlist is distributed under an MIT license. See LICENSE for more details.

Commit count: 29

cargo fmt