浏览代码

Use an iterator to convert the message

Lucas Stadler 10 年之前
父节点
当前提交
6d9d9d168c
共有 1 个文件被更改,包括 2 次插入6 次删除
  1. 2 6
      rust/coffi/src/main.rs

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

@ -34,17 +34,13 @@ impl PNGImage {
34 34
impl std::fmt::Display for PNGImage {
35 35
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
36 36
        fn get_message(msg: [libc::c_char; 64]) -> String {
37
            let mut vec = Vec::new();
38
            for i in 0..64 {
39
                vec.push(msg[i] as u8);
40
            }
41
            String::from_utf8(vec).unwrap()
37
            String::from_utf8(msg.iter().map(|&c| c as u8).collect()).unwrap()
42 38
        }
43 39
44 40
        write!(f, "{}x{} {} {} {} {} {} {}", self.width, self.height, self.version,
45 41
               self.format, self.flags, self.colormap_entries, self.warning_or_error,
46 42
               get_message(self.message))
47
    }
43
        }
48 44
}
49 45
50 46
#[link(name = "png")]