Skip to main content

rlobkit_dialogs/
types.rs

1#[derive(Debug, Clone, Default)]
2pub enum RlobKitType {
3    #[default]
4    Any,
5    Image,
6    Video,
7    ImageAndVideo,
8    Custom {
9        extensions: Vec<String>,
10        mime_types: Vec<String>,
11    },
12}
13
14impl RlobKitType {
15    pub fn extensions(&self) -> Vec<&str> {
16        match self {
17            Self::Any => vec![],
18            Self::Image => vec!["png", "jpg", "jpeg", "gif", "webp", "bmp", "heic"],
19            Self::Video => vec!["mp4", "mov", "avi", "mkv", "webm"],
20            Self::ImageAndVideo => vec![
21                "png", "jpg", "jpeg", "gif", "webp", "bmp", "heic", "mp4", "mov", "avi", "mkv",
22                "webm",
23            ],
24            Self::Custom { extensions, .. } => extensions.iter().map(String::as_str).collect(),
25        }
26    }
27
28    pub fn mime_types(&self) -> Vec<&str> {
29        match self {
30            Self::Any => vec!["*/*"],
31            Self::Image => vec!["image/*"],
32            Self::Video => vec!["video/*"],
33            Self::ImageAndVideo => vec!["image/*", "video/*"],
34            Self::Custom { mime_types, .. } => mime_types.iter().map(String::as_str).collect(),
35        }
36    }
37}