Crates.io | tlnat |
lib.rs | tlnat |
version | 0.1.2 |
source | src |
created_at | 2016-01-06 03:39:09.260365 |
updated_at | 2016-01-07 02:22:42.909441 |
description | type level non-negative integer constants for rust |
homepage | |
repository | https://github.com/daltonwoodard/tlnat |
max_upload_size | |
id | 3835 |
size | 90,655 |
This project is essentially a stop-gap until the rust team implements generics that can be parameterized by values. The infrastructure exists to define other types of objects, but currently the only implemented values are natural numbers 0 through 2048.
author: Dalton Woodard contact: daltonmwoodard@gmail.com license: MIT License (c) 2016 by Dalton Woodard
tlnat requires usage of feature(associated_consts)
and
feature(const_fn)
.
The types each have the format of _n
for some number n >= 0
, along
with the associated constant _n::VALUE
which satisfies _n::VALUE == n
.
Each type provided implements the associated constant VALUE
and the function
pub const fn evaluate () -> T;
which always returns VALUE
.
There are traits IntegralConstant
UnsignedIntegralConstant
, the latter of
which all default types _n
implement.
To define new such types the macros integral_constant!
and
unsigned_integral_constant!
are provided, which take
($name : ident, $val : expr)
as arguments; the types provided by default were
created, for example, by invocation of unsigned_integral_constant!(_0, 0);
.
Currently using _n::VALUE
, although it is indeed a compile-time constant,
to specify the size of a fixed-size array, such as [u8; _n::VALUE]
does not
compile. I believe it is related to the issue discussed in this issue:
https://github.com/rust-lang/rust/issues/25145
If your project uses tlnat please feel free to make a pull request to add to the following list.
Projects using tlnat: