mirror of
https://github.com/chatmail/core.git
synced 2026-05-16 21:36:30 +03:00
Derive and use Display trait for Viewtype
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
use num_traits::{FromPrimitive, ToPrimitive};
|
use num_traits::{FromPrimitive, ToPrimitive};
|
||||||
use rusqlite as sql;
|
use rusqlite as sql;
|
||||||
use rusqlite::types::*;
|
use rusqlite::types::*;
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
pub const DC_VERSION_STR: &'static [u8; 14] = b"1.0.0-alpha.3\x00";
|
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 =
|
pub const DC_LP_SMTP_SOCKET_FLAGS: usize =
|
||||||
(DC_LP_SMTP_SOCKET_STARTTLS | DC_LP_SMTP_SOCKET_SSL | DC_LP_SMTP_SOCKET_PLAIN);
|
(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)]
|
#[repr(i32)]
|
||||||
pub enum Viewtype {
|
pub enum Viewtype {
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
@@ -192,6 +191,16 @@ pub enum Viewtype {
|
|||||||
File = 60,
|
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 {
|
impl ToSql for Viewtype {
|
||||||
fn to_sql(&self) -> sql::Result<ToSqlOutput> {
|
fn to_sql(&self) -> sql::Result<ToSqlOutput> {
|
||||||
let num: i64 = self
|
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
|
// These constants are used as events
|
||||||
// reported to the callback given to dc_context_new().
|
// 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,
|
// If you do not want to handle an event, it is always safe to return 0,
|
||||||
|
|||||||
@@ -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 {
|
if (*msg).type_0 != Viewtype::Text {
|
||||||
ret += "Type: ";
|
ret += "Type: ";
|
||||||
match (*msg).type_0 {
|
ret += &format!("{}", (*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 += "\n";
|
ret += "\n";
|
||||||
p = dc_msg_get_filemime(msg);
|
p = dc_msg_get_filemime(msg);
|
||||||
ret += &format!("Mimetype: {}\n", as_str(p));
|
ret += &format!("Mimetype: {}\n", as_str(p));
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ extern crate num_derive;
|
|||||||
extern crate smallvec;
|
extern crate smallvec;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rusqlite;
|
extern crate rusqlite;
|
||||||
|
extern crate strum;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate strum_macros;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod log;
|
mod log;
|
||||||
|
|||||||
Reference in New Issue
Block a user