wallhaven_rs/models/request/search/query.rs
1use std::{fmt::Display, str::FromStr};
2
3use crate::FileType;
4
5/// A single search query item
6#[derive(Clone, Debug)]
7pub enum SearchQueryItem {
8 /// Fuzzily search for a tag/keyword
9 ///
10 /// On the web UI, this corresponds to `tag`
11 Fuzz(String),
12 /// Exclude a tag/keyword
13 ///
14 /// On the web UI, this corresponds to `-tag`
15 Exclude(String),
16 /// Exact tag match, without the fuzzy search
17 ///
18 /// On the web UI, this corresponds to `+tag`
19 Exact(String),
20 /// Exact uploader match
21 ///
22 /// On the web UI, this corresponds to `@username`
23 FromUser(String),
24 /// Exact tag id search (cannot be combined)
25 ///
26 /// On the web UI, this corresponds to `id:123`
27 TagById(u64),
28 /// The wallpaper file type
29 ///
30 /// On the web UI, this corresponds to `type:{jpg/png}`
31 FileType(FileType),
32 /// Find wallpapers with similar tags
33 ///
34 /// On the web UI, this corresponds to `like:{wallpaper_id}`
35 LikeWallpaper(String),
36}
37
38impl Display for SearchQueryItem {
39 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40 match self {
41 Self::Fuzz(s) => write!(f, "{s}",),
42 Self::Exclude(s) => write!(f, "-{s}"),
43 Self::Exact(s) => write!(f, "+{s}"),
44 Self::FromUser(u) => write!(f, "@{u}"),
45 Self::TagById(id) => write!(f, "id:{id}"),
46 Self::FileType(s) => write!(f, "type:{s}"),
47 Self::LikeWallpaper(s) => write!(f, "like:{s}"),
48 }
49 }
50}
51
52impl FromStr for SearchQueryItem {
53 type Err = std::convert::Infallible;
54
55 fn from_str(_: &str) -> Result<Self, Self::Err> {
56 unreachable!()
57 }
58}