#slice #typecast

yanked slice-cast

Support for casting between slice types

Uses old Rust 2015

0.1.2 Dec 8, 2016
0.1.1 Dec 8, 2016
0.1.0 Dec 5, 2016

#98 in #slice

45 downloads per month
Used in 4 crates (2 directly)

Apache-2.0/MIT

11KB
153 lines

slice-cast

Build Status crates.io docs.rs

This Rust library provides support for performing cast operations on slices.

The cast() and cast_mut() functions perform casts between slice types:

extern crate slice_cast;

fn main() {
    let foo: [u8; 4] = [1, 0, 0, 0];
    let bar: &[u32] = unsafe { slice_cast::cast(&foo) };
    println!("{:?}", bar);
}

The cast_to() and cast_to_mut() functions perform casts from slices into concrete types:

extern crate slice_cast;

fn main() {
    let foo: [u8; 4] = [1, 0, 0, 0];
    let bar: &u32 = unsafe { slice_cast::cast_to(&foo) };
    println!("{}", bar);
}

Usage

Add the following line to your [dependencies] in Cargo.toml:

slice-cast = "0.1"

And add the following line to your crate root:

extern crate slice_cast;

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies