diff --git a/src/constants.rs b/src/constants.rs index e72019174..e055dc73d 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -3,7 +3,6 @@ use num_traits::{FromPrimitive, ToPrimitive}; use rusqlite as sql; use rusqlite::types::*; -use std::fmt; pub const DC_VERSION_STR: &'static [u8; 14] = b"1.0.0-alpha.3\x00"; @@ -147,7 +146,7 @@ pub const DC_LP_IMAP_SOCKET_FLAGS: usize = pub const DC_LP_SMTP_SOCKET_FLAGS: usize = (DC_LP_SMTP_SOCKET_STARTTLS | DC_LP_SMTP_SOCKET_SSL | DC_LP_SMTP_SOCKET_PLAIN); -#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)] +#[derive(Debug, Display, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)] #[repr(i32)] pub enum Viewtype { Unknown = 0, @@ -192,6 +191,16 @@ pub enum Viewtype { File = 60, } +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn derive_display_works_as_expected() { + assert_eq!(format!("{}", Viewtype::Audio), "Audio"); + } +} + impl ToSql for Viewtype { fn to_sql(&self) -> sql::Result { let num: i64 = self @@ -209,17 +218,6 @@ impl FromSql for Viewtype { } } -impl fmt::Display for Viewtype { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "{}", - self.to_i64() - .expect("impossible: Viewtype -> i64 conversion failed") - ) - } -} - // These constants are used as events // reported to the callback given to dc_context_new(). // If you do not want to handle an event, it is always safe to return 0, diff --git a/src/dc_msg.rs b/src/dc_msg.rs index 150d389ef..66e404680 100644 --- a/src/dc_msg.rs +++ b/src/dc_msg.rs @@ -179,15 +179,7 @@ pub unsafe fn dc_get_msg_info(context: &Context, msg_id: u32) -> *mut libc::c_ch if (*msg).type_0 != Viewtype::Text { ret += "Type: "; - match (*msg).type_0 { - Viewtype::Audio => ret += "Audio", - Viewtype::File => ret += "File", - Viewtype::Gif => ret += "GIF", - Viewtype::Image => ret += "Image", - Viewtype::Video => ret += "Video", - Viewtype::Voice => ret += "Voice", - _ => ret += &format!("{}", (*msg).type_0), - } + ret += &format!("{}", (*msg).type_0); ret += "\n"; p = dc_msg_get_filemime(msg); ret += &format!("Mimetype: {}\n", as_str(p)); diff --git a/src/lib.rs b/src/lib.rs index bf361ae0d..f735de035 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,9 @@ extern crate num_derive; extern crate smallvec; #[macro_use] extern crate rusqlite; +extern crate strum; +#[macro_use] +extern crate strum_macros; #[macro_use] mod log;