0
0
mirror of https://github.com/rust-lang/rust.git synced 2024-11-24 18:21:15 +01:00
rust/tests/run-make/extern-fn-slice-no-ice/test.rs
2024-07-17 15:33:06 -04:00

19 lines
520 B
Rust

#[link(name = "test", kind = "static")]
extern "C" {
fn slice_len(s: &[u8]) -> usize;
fn slice_elem(s: &[u8], idx: usize) -> u8;
}
fn main() {
let data = [1, 2, 3, 4, 5];
unsafe {
assert_eq!(data.len(), slice_len(&data) as usize);
assert_eq!(data[0], slice_elem(&data, 0));
assert_eq!(data[1], slice_elem(&data, 1));
assert_eq!(data[2], slice_elem(&data, 2));
assert_eq!(data[3], slice_elem(&data, 3));
assert_eq!(data[4], slice_elem(&data, 4));
}
}