Browse Source

Rename png_image to PNGImage

To conform to the rust style of naming things.
Lucas Stadler 10 years ago
parent
commit
f7ec2ddc92
1 changed files with 7 additions and 7 deletions
  1. 7 7
      rust/coffi/src/main.rs

+ 7 - 7
rust/coffi/src/main.rs

7
}
7
}
8
8
9
#[repr(C)]
9
#[repr(C)]
10
struct png_image {
10
struct PNGImage {
11
    opaque: *mut libc::c_void,
11
    opaque: *mut libc::c_void,
12
    version: libc::c_uint,
12
    version: libc::c_uint,
13
    width: libc::c_uint,
13
    width: libc::c_uint,
19
    message: [libc::c_char; 64],
19
    message: [libc::c_char; 64],
20
}
20
}
21
21
22
impl png_image {
23
    fn new() -> png_image {
24
        let mut img: png_image = unsafe { std::mem::zeroed() };
22
impl PNGImage {
23
    fn new() -> PNGImage {
24
        let mut img: PNGImage = unsafe { std::mem::zeroed() };
25
        img.version = 1;
25
        img.version = 1;
26
        return img
26
        return img
27
    }
27
    }
31
    }
31
    }
32
}
32
}
33
33
34
impl std::fmt::Display for png_image {
34
impl std::fmt::Display for PNGImage {
35
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
35
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
36
        fn get_message(msg: [libc::c_char; 64]) -> String {
36
        fn get_message(msg: [libc::c_char; 64]) -> String {
37
            let mut vec = Vec::new();
37
            let mut vec = Vec::new();
49
49
50
#[link(name = "png")]
50
#[link(name = "png")]
51
extern {
51
extern {
52
    fn png_image_begin_read_from_file(img: *mut png_image, file_name: *const libc::c_char) -> libc::c_int;
52
    fn png_image_begin_read_from_file(img: *mut PNGImage, file_name: *const libc::c_char) -> libc::c_int;
53
}
53
}
54
54
55
fn main() {
55
fn main() {
57
    println!("cos(3.1415) = {}", x);
57
    println!("cos(3.1415) = {}", x);
58
    println!("");
58
    println!("");
59
59
60
    let mut img = png_image::new();
60
    let mut img = PNGImage::new();
61
    let file_name = std::env::args().nth(1).unwrap_or(String::from("mei.png"));
61
    let file_name = std::env::args().nth(1).unwrap_or(String::from("mei.png"));
62
    let c_name = std::ffi::CString::new(file_name).unwrap();
62
    let c_name = std::ffi::CString::new(file_name).unwrap();
63
    let res = img.begin_read_from_file(c_name.as_ptr());
63
    let res = img.begin_read_from_file(c_name.as_ptr());