LoginSignup
0
2

More than 5 years have passed since last update.

Cの配列をコピーしてVec型の変数を作る

Last updated at Posted at 2017-09-12

背景

画像の配列にありがちなunsigned charの配列をRustな型にするには

ptrがunsigned char*

ptr: *mut c_uchar

これをRustのu8の配列に変換する。

offsetメソッドでポインタのアドレスをずらせる模様。

let mut buf: Vec<u8> = Vec::new();
for i in 0..len {
        buf.push(unsafe { *(ptr.offset(i as isize)) });
}

関連記事

0
2
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2