Crate infer_len[−][src]
Expand description
“Infer” the lengths of arrays in static
/const
items.
Crate feature
-
no-core
: Make this crate#![no_core]
.#![no_core]
example#![feature(no_core, lang_items, start)] #![no_core] #[cfg_attr(not(windows), link(name = "c"))] #[cfg_attr(windows, link(name = "msvcrt"))] extern "C" {} use infer_len::infer_len; #[lang = "sized"] trait Sized {} #[lang = "eh_personality"] fn eh_personality() -> ! { loop {} } #[lang = "receiver"] trait Receiver {} impl<T: ?Sized> Receiver for &T {} #[lang = "array"] impl [i32; 5] { const fn len(&self) -> usize { 5 } } infer_len! { const FOO: [i32] = [1, 2, 3, 4, 5]; const BAR: [i32] = [6, 7, 8, 9, 10]; } #[start] fn main(_: isize, _: *const *const u8) -> isize { let _: [i32; 5] = FOO; let _: [i32; 5] = BAR; 0 }
Example
use std::convert; infer_len! { pub(self) const FOO: [i128] = [-1, -2, -3, -4]; const BAR: [i128] = FOO; pub static BAZ: [i128] = BAR; #[allow(non_upper_case_globals)] // attribute works static qux: [i128] = convert::identity(BAR); // arbitrary expression works #[allow(non_upper_case_globals)] #[used] // multiple attributes works static used: [i128] = FOO; } let _: [i128; 4] = FOO; let _: [i128; 4] = BAR; let _: [i128; 4] = BAZ; let _: [i128; 4] = qux;
Macros
infer_len | The main macro of this crate. |