inline-const
You don't want to wait until inline consts are stable? This crate offers much of the functionality of inline consts in a pure macro-based implementation, at a slight const of convenience: you need to explicitly annotate the type of the constant.
use Ipv6Addr;
use inline_const;
Unlike the current unstable implementation of inline-const, this crate even supports consts that depend on generic parameters, albeit at some further annotation cost: you need to repeat the generic parameters that the constant refers to, and their lifetime bounds.
use inline_const;
Static assertions
This can be used to implement static assertions that depend on generic parameters:
use inline_const;
const
// When an inline const depends on both types and const generics, a `;` must be used
// to separate the two.
;
//size_at_least_2::<i8>();
;
//const_at_least_2::<1>();
;
//size_at_least::<i8, 2>();
Array of constants
Since recently, [C; N]
works for any constant C
, even for non-Copy
types.
However, without inline consts, this is somewhat annoying to use.
This crate offers the const_array!
macro to help with that situation:
use const_array;