Add code
This commit is contained in:
1
example_11/.gitignore
vendored
Normal file
1
example_11/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
6
example_11/Cargo.toml
Normal file
6
example_11/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "example_11"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
14
example_11/src/main.rs
Normal file
14
example_11/src/main.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use std::slice;
|
||||
|
||||
fn main() {
|
||||
let some_vector = vec![1, 2, 3, 4];
|
||||
|
||||
let pointer = some_vector.as_ptr();
|
||||
let length = some_vector.len();
|
||||
|
||||
unsafe {
|
||||
let my_slice: &[u32] = slice::from_raw_parts(pointer, length);
|
||||
|
||||
assert_eq!(some_vector.as_slice(), my_slice);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user