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. ```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() -> &'static Vec{ inline_const! { [&'static Vec] &Vec::new() } } ```

Static assertions

This can be used to implement static assertions that depend on generic parameters: ```rust use inlineconst::inlineconst;

[allow(unconditional_panic)]

const fn assert(b: bool) { if !b { ["const assertion failed"][1]; } }

fn sizeatleast2() { inlineconst!{ [()] assert(std::mem::sizeof::() >= 2)}; } fn constatleast2() { inlineconst!{ [()] assert(N >= 2)}; } // When an inline const depends on both types and const generics, a ; must be used // to separate the two. fn sizeatleast() { inlineconst!{ [()] assert(std::mem::size_of::() >= N)}; }

sizeatleast2::(); //sizeatleast2::(); constatleast2::<4>(); //constatleast2::<1>(); sizeatleast::(); //sizeatleast::(); ```

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:

```rust use inlineconst::constarray;

fn makei32vecs() -> [Vec; 5] { // [Vec::new(); 5]: rejected since Vec::new is not a constant. constarray![ [Vec] Vec::new(); 5] } fn makevecs() -> [Vec; 5] { // Generic parameters used in the const expression must be explicitly specified: constarray![ [Vec] Vec::new(); 5] } fn makenvecs() -> [Vec; N] { constarray![ [Vec] Vec::new(); N] } ```