pl-hlist

Build Status

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:

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

Usage

Add a dependency to your Cargo.toml:

toml [dependencies] pl-hlist = "1.0.0"

Then, in your crate:

rust use pl_hlist::*;

An HList can be constructed manually as follows:

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

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

rust 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:

```rust

[derive(HListSupport)]

struct TestStruct { foo: u8, bar: u32 }

let hlist0 = hlist!(1u8, 666u32); let s = TestStruct::fromhlist(hlist0); asserteq!(s.foo, 1u8); asserteq!(s.bar, 666u32); let hlist1 = s.intohlist(); assert_eq!(hlist0, hlist1); ```

License

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