Pārlūkot izejas kodu

Put message conversion into a method

Lucas Stadler 10 gadi atpakaļ
vecāks
revīzija
9716e26c45
1 mainītis faili ar 7 papildinājumiem un 5 dzēšanām
  1. 7 5
      rust/coffi/src/main.rs

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

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
impl std::fmt::Display for PNGImage {
40
impl std::fmt::Display for PNGImage {
35
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
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
        write!(f, "{}x{} {} {} {} {} {} {}", self.width, self.height, self.version,
42
        write!(f, "{}x{} {} {} {} {} {} {}", self.width, self.height, self.version,
41
               self.format, self.flags, self.colormap_entries, self.warning_or_error,
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