Skip to main content

typed_slice

Macro typed_slice 

Source
macro_rules! typed_slice {
    ($($x:expr),* $(,)?) => { ... };
}
Expand description

Creates a reference to a TypedSlice containing the arguments.

This macro creates a temporary array and returns a reference to it as a TypedSlice. Note that due to how temporary lifetimes work in Rust, the returned reference is only valid for the duration of the statement it is in, unless it is immediately bound to a let variable.

ยงUsage Example

use index_type::{IndexType, typed_slice};
use index_type::typed_slice::TypedSlice;

#[derive(IndexType, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct MyIndex(u32);

let s: &TypedSlice<MyIndex, i32> = typed_slice![1, 2, 3];
assert_eq!(s.len_usize(), 3);