#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

#231 in #slice

Download history 258/week @ 2024-11-24 257/week @ 2024-12-01 386/week @ 2024-12-08 413/week @ 2024-12-15 123/week @ 2024-12-22 60/week @ 2024-12-29 357/week @ 2025-01-05 562/week @ 2025-01-12 474/week @ 2025-01-19 173/week @ 2025-01-26 439/week @ 2025-02-02 557/week @ 2025-02-09 214/week @ 2025-02-16 442/week @ 2025-02-23 195/week @ 2025-03-02 273/week @ 2025-03-09

1,215 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