Skip to content

Implementation without unsafe is possible #18

Open
@Shnatsel

Description

@Shnatsel

It is now possible to implement this macro safely thanks to TryInto implementation from slices to array references:

let my_arr_reference: &[i32; 5] = my_slice.try_into().unwrap();

Bounds checks will also be elided if the size of the slice is known in advance.

Example of this conversion in action: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=9d6e1d61835060f832ce1724becb1214

The only limitation is that this only works for sizes of 32 and lower until const generics are stabilized.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions