Skip to main content

resourcespace_client/api/
mod.rs

1pub mod collection;
2pub mod message;
3pub mod metadata;
4pub mod resource;
5pub mod search;
6pub mod system;
7pub mod user;
8
9use serde::Serialize;
10use serde_with::{StringWithSeparator, formats::CommaSeparator, serde_as};
11use std::fmt::Display;
12
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
14#[serde(rename_all = "lowercase")]
15pub enum SortOrder {
16    Asc,
17    Desc,
18}
19
20/// A list of values that serializes to a comma-separated string.
21///
22/// Accepts a single value, an array, or a [`Vec`] via [`Into`] conversions,
23/// making it ergonomic to pass one or many values at call sites:
24///
25/// ```no_run
26/// List::from(42)               // single value
27/// List::from([1, 2, 3])        // array
28/// List::from(vec![1, 2, 3])    // vec
29/// ```
30///
31/// This type exists to satisfy ResourceSpace API parameters that expect
32/// comma-separated values (e.g. `"1,2,3"`), while keeping call sites
33/// type-safe and free of manual string joining.
34#[serde_as]
35#[derive(Serialize, Debug, Clone, PartialEq)]
36pub struct List<T: Display>(#[serde_as(as = "StringWithSeparator::<CommaSeparator, T>")] Vec<T>);
37
38// u32
39impl From<u32> for List<u32> {
40    fn from(val: u32) -> Self {
41        Self(vec![val])
42    }
43}
44impl From<Vec<u32>> for List<u32> {
45    fn from(vals: Vec<u32>) -> Self {
46        Self(vals)
47    }
48}
49impl<const N: usize> From<[u32; N]> for List<u32> {
50    fn from(arr: [u32; N]) -> Self {
51        Self(arr.into_iter().collect())
52    }
53}
54
55// String
56impl From<String> for List<String> {
57    fn from(val: String) -> Self {
58        Self(vec![val])
59    }
60}
61impl From<&str> for List<String> {
62    fn from(val: &str) -> Self {
63        Self(vec![val.to_string()])
64    }
65}
66impl From<Vec<String>> for List<String> {
67    fn from(vals: Vec<String>) -> Self {
68        Self(vals)
69    }
70}
71impl From<Vec<&str>> for List<String> {
72    fn from(vals: Vec<&str>) -> Self {
73        Self(vals.into_iter().map(|s| s.to_string()).collect())
74    }
75}
76impl<const N: usize> From<[String; N]> for List<String> {
77    fn from(arr: [String; N]) -> Self {
78        Self(arr.into_iter().collect())
79    }
80}
81impl<const N: usize> From<[&str; N]> for List<String> {
82    fn from(arr: [&str; N]) -> Self {
83        Self(arr.into_iter().map(|s| s.to_string()).collect())
84    }
85}