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. ```rust use std::net::Ipv6Addr;
use inlineconst::inlineconst;
fn mockip(uselocalhost: bool) -> &'static Ipv6Addr { if uselocalhost { &Ipv6Addr::LOCALHOST } else { inlineconst! { [&'static Ipv6Addr] &Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0) } } } ```
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. ```rust use inlineconst::inlineconst;
fn makestaticvec
This can be used to implement static assertions that depend on generic parameters: ```rust use inlineconst::inlineconst;
const fn assert(b: bool) { if !b { ["const assertion failed"][1]; } }
fn sizeatleast2;
must be used
// to separate the two.
fn size
sizeatleast2::
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:
```rust use inlineconst::constarray;
fn makei32vecs() -> [VecVec::new
is not a constant.
constarray![ [Vec