icon_loader/
search_paths.rs1use std::{borrow::Cow, path::PathBuf};
2
3use xdg::BaseDirectories;
4
5#[derive(Clone, Debug, Default, PartialEq, Eq)]
7pub enum SearchPaths {
8 #[default]
10 System,
11
12 Custom(Vec<PathBuf>),
14}
15
16impl SearchPaths {
17 pub fn custom<I, P>(iter: I) -> Self
19 where
20 I: IntoIterator<Item = P>,
21 P: Into<PathBuf>,
22 {
23 SearchPaths::Custom(iter.into_iter().map(P::into).collect())
24 }
25
26 pub(crate) fn paths(&self) -> Cow<[PathBuf]> {
27 match self {
28 SearchPaths::System => {
29 Cow::Owned(BaseDirectories::with_prefix("icons").get_data_dirs())
30 }
31 SearchPaths::Custom(dirs) => Cow::Borrowed(dirs),
32 }
33 }
34}
35
36impl<I, P> From<I> for SearchPaths
37where
38 I: IntoIterator<Item = P>,
39 P: Into<PathBuf>,
40{
41 fn from(iter: I) -> Self {
42 SearchPaths::custom(iter)
43 }
44}