rust/tests/ui/rfcs/rfc-1789-as-cell/from-mut.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

21 lines
529 B
Rust
Raw Normal View History

// run-pass
2018-05-07 02:24:45 -05:00
#![feature(as_array_of_cells)]
2018-05-07 02:24:45 -05:00
use std::cell::Cell;
fn main() {
2018-05-28 01:35:12 -05:00
let slice: &mut [i32] = &mut [1, 2, 3];
2018-05-07 02:24:45 -05:00
let cell_slice: &Cell<[i32]> = Cell::from_mut(slice);
2018-07-23 06:20:50 -05:00
let slice_cell: &[Cell<i32>] = cell_slice.as_slice_of_cells();
2018-05-28 01:35:12 -05:00
2018-07-23 06:20:50 -05:00
assert_eq!(slice_cell.len(), 3);
let mut array: [i32; 3] = [1, 2, 3];
let cell_array: &Cell<[i32; 3]> = Cell::from_mut(&mut array);
let array_cell: &[Cell<i32>; 3] = cell_array.as_array_of_cells();
array_cell[0].set(99);
assert_eq!(array, [99, 2, 3]);
2018-05-07 02:24:45 -05:00
}