Selaa lähdekoodia

Move png_image initialization into a function

Lucas Stadler 10 vuotta sitten
vanhempi
commit
8c7c2d2feb
1 muutettua tiedostoa jossa 9 lisäystä ja 2 poistoa
  1. 9 2
      rust/coffi/src/main.rs

+ 9 - 2
rust/coffi/src/main.rs

@ -19,6 +19,14 @@ struct png_image {
19 19
    message: [u8; 64],
20 20
}
21 21
22
impl png_image {
23
    fn new() -> png_image {
24
        let mut img: png_image = unsafe { std::mem::zeroed() };
25
        img.version = 1;
26
        return img
27
    }
28
}
29
22 30
impl std::fmt::Display for png_image {
23 31
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
24 32
        fn get_message(msg: [u8; 64]) -> String {
@ -45,8 +53,7 @@ fn main() {
45 53
    println!("cos(3.1415) = {}", x);
46 54
47 55
    unsafe {
48
        let mut img: png_image = std::mem::zeroed();
49
        img.version = 1;
56
        let mut img = png_image::new();
50 57
        println!("{}", img);
51 58
        let res = png_image_begin_read_from_file(&mut img, "mei.png\0".as_ptr());
52 59
        println!("read_from_file: {}", res);