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

Put message conversion into a method

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

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

@ -31,15 +31,17 @@ impl PNGImage {
31 31
    }
32 32
}
33 33
34
impl PNGImage {
35
    fn message(&self) -> String {
36
        String::from_utf8(self.message.iter().map(|&c| c as u8).collect()).unwrap()
37
    }
38
}
39
34 40
impl std::fmt::Display for PNGImage {
35 41
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
36
        fn get_message(msg: [libc::c_char; 64]) -> String {
37
            String::from_utf8(msg.iter().map(|&c| c as u8).collect()).unwrap()
38
        }
39
40 42
        write!(f, "{}x{} {} {} {} {} {} {}", self.width, self.height, self.version,
41 43
               self.format, self.flags, self.colormap_entries, self.warning_or_error,
42
               get_message(self.message))
44
               self.message())
43 45
        }
44 46
}
45 47