How to initial struct array!

Here is my code:

pub struct BDFaceBox {
    /// `index` 人脸索引值
    index: c_int,
    /// `center_x` 人脸中心点x坐标
    center_x: c_float,
    /// `center_y` 人脸中心点y坐标
    center_y: c_float,
    /// `width` 人脸宽度
    width: c_float,
    /// `height` 人脸高度
    height: c_float,
    /// `angle` 人脸角度
    angle: c_float,
    /// `score` 人脸置信度
    score: c_float,
}

let face_box: [*mut BDFaceBox; 3];

How to init face_box variable

The simplest answer to your question is face_box = [std::ptr::null_mut(); 3], but that is likely not what you want— Idiomatic rust would probably be to use [BDFaceBox; 3] instead:

let face_box = [
    BDFaceBox {
        index: ...,
        center_x:...,
        ...
    },
    BDFaceBox { ... },
    BDFaceBox { ... },
];

Can you describe a little more about what you're trying to do?

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.