#slice #static #macro #type

static_slice

Macro for creating static slices of arbitrary types

3 releases

Uses old Rust 2015

0.0.3 Apr 4, 2017
0.0.2 Apr 3, 2015
0.0.1 Jan 17, 2015

#197 in #slice

Download history 170/week @ 2023-11-27 163/week @ 2023-12-04 197/week @ 2023-12-11 261/week @ 2023-12-18 165/week @ 2023-12-25 90/week @ 2024-01-01 231/week @ 2024-01-08 219/week @ 2024-01-15 189/week @ 2024-01-22 133/week @ 2024-01-29 203/week @ 2024-02-05 253/week @ 2024-02-12 245/week @ 2024-02-19 265/week @ 2024-02-26 302/week @ 2024-03-04 115/week @ 2024-03-11

959 downloads per month
Used in 8 crates (via i2p_snow)

WTFPL license

2KB

Static Slice

Rust macro for succinctly creating static slices.

Usage

static_slice![<type>: a1, a2, ..., an]

Examples

let bytes = static_slice![u8: 1, 3, 5, 7, 8];
enum TruthValue {
    Yes,
    Maybe,
    No
}

fn to_bools(x: TruthValue) -> &'static [bool] {
    match x {
        Yes => static_slice![true],
        Maybe => static_slice![true, false],
        No => static_slice![false]
    }
}

License

Public domain. Go for it.


lib.rs:

Just a single macro. See below.

No runtime deps