Skip to content

natfoam/lib

Repository files navigation

lib

Netlify Status CircleCI

Documentation:

Rust libraries:

  • fixed-array is a trait for fixed-size arrays.
  • uints are traits and extensions for different unsigned integer types.
  • list-fn is a lazy-list as an alternative to the standard Rust iterator.
  • bit-list is an LSB-first list of bits.
  • sha2-compress is an SHA2 compress function.
  • u144 is an unsigned integer 144 bit. For example, to store 137 bit blocks 🙄.
  • publish-ws is a tool for publishing all workspace packages.

Conventions

  • a Fn suffix is used for traits. For example, ListFn.
  • a name of an extension function is used for its trait. For example
    trait Fold: ListFn {
        fn fold(self) -> Self::End { ... }
    }
    impl<T: ListFn> Fold for T {}
    An alternative is to use Sugar suffix:
    trait FoldSugar: ListFn {
        fn fold(self) -> Self::End { ... }
    }
    impl<T: ListFn> FoldSugar for T {}

Rust Wish List

  • const fn in traits. For example
    trait X {
        const fn x() -> X;
    }
  • default types in traits
    trait X {
        type M = u8
    }
  • impl Type in traits almost like dyn.
    trait X {
        type M = impl R;
    }
  • defining arrays in traits using parameters
    trait X<const N: usize> {
        fn x() -> [u8; N];
    }
  • Generators. See genawaiter as an example.