libmtp_rs/object/
filetypes.rs

1//! Contains all the filetypes that `libmtp` claims to support and can handle.
2//! Note that some devices may not support some filetypes.
3
4use libmtp_sys as ffi;
5use num_derive::{FromPrimitive, ToPrimitive};
6use num_traits::ToPrimitive;
7use std::ffi::CStr;
8use std::fmt::{self, Display};
9
10/// Enumeration that holds the supported filetypes, this enum implements `Display`
11/// with the description of the file type.
12#[derive(Debug, Clone, FromPrimitive, ToPrimitive)]
13pub enum Filetype {
14    Folder = 0,
15    Wav,
16    Mp3,
17    Wma,
18    Ogg,
19    Audible,
20    Mp4,
21    UndefAudio,
22    Wmv,
23    Avi,
24    Mpeg,
25    Asf,
26    Qt,
27    UndefVideo,
28    Jpeg,
29    Jfif,
30    Tiff,
31    Bmp,
32    Gif,
33    Pict,
34    Png,
35    VCalendar1,
36    VCalendar2,
37    VCard2,
38    VCard3,
39    WindowsImageFormat,
40    WinExec,
41    Text,
42    Html,
43    Firmware,
44    Aac,
45    MediaCard,
46    Flac,
47    Mp2,
48    M4a,
49    Doc,
50    Xml,
51    Xls,
52    Ppt,
53    Mht,
54    Jp2,
55    Jpx,
56    Album,
57    Playlist,
58    Unknown,
59}
60
61impl Display for Filetype {
62    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63        let ftype = self.to_u32().unwrap();
64
65        unsafe {
66            let desc = ffi::LIBMTP_Get_Filetype_Description(ftype);
67            let cstr = CStr::from_ptr(desc);
68
69            write!(f, "{}", cstr.to_str().unwrap())
70        }
71    }
72}