Просмотр исходного кода

Move png_image initialization into a function

Lucas Stadler лет назад: 10
Родитель
Сommit
8c7c2d2feb
1 измененных файлов с 9 добавлено и 2 удалено
  1. 9 2
      rust/coffi/src/main.rs

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

19
    message: [u8; 64],
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
impl std::fmt::Display for png_image {
30
impl std::fmt::Display for png_image {
23
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
31
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
24
        fn get_message(msg: [u8; 64]) -> String {
32
        fn get_message(msg: [u8; 64]) -> String {
45
    println!("cos(3.1415) = {}", x);
53
    println!("cos(3.1415) = {}", x);
46
54
47
    unsafe {
55
    unsafe {
48
        let mut img: png_image = std::mem::zeroed();
49
        img.version = 1;
56
        let mut img = png_image::new();
50
        println!("{}", img);
57
        println!("{}", img);
51
        let res = png_image_begin_read_from_file(&mut img, "mei.png\0".as_ptr());
58
        let res = png_image_begin_read_from_file(&mut img, "mei.png\0".as_ptr());
52
        println!("read_from_file: {}", res);
59
        println!("read_from_file: {}", res);