hugging_face_client/
repo.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
4pub enum RepoType {
5  #[serde(rename = "dataset")]
6  Dataset,
7
8  #[serde(rename = "space")]
9  Space,
10
11  #[serde(rename = "model")]
12  Model,
13}
14
15impl Default for RepoType {
16  fn default() -> Self {
17    RepoType::Model
18  }
19}
20
21#[cfg(test)]
22mod test {
23  use std::assert_matches::assert_matches;
24
25  use crate::repo::RepoType;
26
27  #[test]
28  fn test_serde_repo_type() {
29    let repo_type = RepoType::Dataset;
30    let json = serde_json::to_string(&repo_type);
31    assert_matches!(json, Ok(v) if v == "\"dataset\"");
32
33    let json = "\"dataset\"";
34    let sdk = serde_json::from_str::<RepoType>(json);
35    assert_matches!(sdk, Ok(RepoType::Dataset));
36
37    let repo_type = RepoType::Space;
38    let json = serde_json::to_string(&repo_type);
39    assert_matches!(json, Ok(v) if v == "\"space\"");
40
41    let json = "\"space\"";
42    let sdk = serde_json::from_str::<RepoType>(json);
43    assert_matches!(sdk, Ok(RepoType::Space));
44
45    let repo_type = RepoType::Model;
46    let json = serde_json::to_string(&repo_type);
47    assert_matches!(json, Ok(v) if v == "\"model\"");
48
49    let json = "\"model\"";
50    let sdk = serde_json::from_str::<RepoType>(json);
51    assert_matches!(sdk, Ok(RepoType::Model));
52  }
53}