hugging_face_client/api/
get_models.rs1use serde::Serialize;
2
3use crate::{model::Model, tag::ModelTag};
4
5#[derive(Debug, Default, Serialize)]
7pub struct GetModelsReq<'a> {
8 #[serde(skip_serializing_if = "Option::is_none")]
9 search: Option<&'a str>,
10
11 #[serde(skip_serializing_if = "Option::is_none")]
12 author: Option<&'a str>,
13
14 #[serde(skip_serializing_if = "Option::is_none")]
15 filter: Option<&'a str>,
16
17 #[serde(skip_serializing_if = "Option::is_none")]
18 sort: Option<&'a str>,
19
20 #[serde(skip_serializing_if = "Option::is_none")]
21 direction: Option<i32>,
22
23 #[serde(skip_serializing_if = "Option::is_none")]
24 limit: Option<usize>,
25
26 #[serde(skip_serializing_if = "Option::is_none")]
27 full: Option<bool>,
28
29 #[serde(skip_serializing_if = "Option::is_none")]
30 config: Option<bool>,
31}
32
33impl<'a> GetModelsReq<'a> {
34 pub fn search(mut self, search: &'a str) -> Self {
35 self.search = Some(search);
36 self
37 }
38
39 pub fn author(mut self, author: &'a str) -> Self {
40 self.author = Some(author);
41 self
42 }
43
44 pub fn filter(mut self, filter: &'a str) -> Self {
45 self.filter = Some(filter);
46 self
47 }
48
49 pub fn sort(mut self, sort: &'a str) -> Self {
50 self.sort = Some(sort);
51 self
52 }
53
54 pub fn direction(mut self, direction: i32) -> Self {
55 self.direction = Some(direction);
56 self
57 }
58
59 pub fn limit(mut self, limit: usize) -> Self {
60 self.limit = Some(limit);
61 self
62 }
63
64 pub fn full(mut self, full: bool) -> Self {
65 self.full = Some(full);
66 self
67 }
68
69 pub fn config(mut self, config: bool) -> Self {
70 self.config = Some(config);
71 self
72 }
73}
74
75pub type GetModelsRes = Vec<Model>;
77
78#[cfg(test)]
79mod test {
80 use std::assert_matches::assert_matches;
81
82 use crate::api::GetModelsReq;
83
84 #[test]
85 fn test_serde_req() {
86 let req: GetModelsReq = GetModelsReq::default()
87 .search("1")
88 .author("2")
89 .filter("3")
90 .sort("4")
91 .direction(1)
92 .limit(100)
93 .full(true)
94 .config(true);
95 let query = serde_urlencoded::to_string(req);
96 assert_matches!(query, Ok(v) if v == "search=1&author=2&filter=3&sort=4&direction=1&limit=100&full=true&config=true");
97 }
98}