linera_witty

Trait HList

Source
pub trait HList: Sized {
    const LEN: usize;

    // Required method
    fn static_len() -> usize;

    // Provided methods
    fn len(&self) -> usize { ... }
    fn is_empty(&self) -> bool { ... }
    fn prepend<H>(self, h: H) -> HCons<H, Self> { ... }
}
Expand description

Typeclass for HList-y behaviour

An HList is a heterogeneous list, one that is statically typed at compile time. In simple terms, it is just an arbitrarily-nested Tuple2.

Required Associated Constants§

Source

const LEN: usize

Returns the length of a given HList type without making use of any references, or in fact, any values at all.

§Examples
use frunk::prelude::*;
use frunk_core::HList;

assert_eq!(<HList![i32, bool, f32]>::LEN, 3);

Required Methods§

Source

fn static_len() -> usize

👎Deprecated since 0.1.31: Please use LEN instead

Returns the length of a given HList type without making use of any references, or in fact, any values at all.

§Examples
use frunk::prelude::*;
use frunk_core::HList;

assert_eq!(<HList![i32, bool, f32]>::static_len(), 3);

Provided Methods§

Source

fn len(&self) -> usize

Returns the length of a given HList

§Examples
use frunk_core::hlist;

let h = hlist![1, "hi"];
assert_eq!(h.len(), 2);
Source

fn is_empty(&self) -> bool

Returns whether a given HList is empty

§Examples
use frunk_core::hlist;

let h = hlist![];
assert!(h.is_empty());
Source

fn prepend<H>(self, h: H) -> HCons<H, Self>

Prepends an item to the current HList

§Examples
use frunk_core::hlist;

let h1 = hlist![1, "hi"];
let h2 = h1.prepend(true);
let (a, (b, c)) = h2.into_tuple2();
assert_eq!(a, true);
assert_eq!(b, 1);
assert_eq!(c, "hi");

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl HList for HNil

Source§

const LEN: usize = 0usize

Source§

impl<H, T> HList for HCons<H, T>
where T: HList,

Source§

const LEN: usize = _