maven_search_lib/
types.rs

1use serde::Deserialize;
2
3#[derive(Debug)]
4pub enum MavenError<'a> {
5    Args(getargs::Error<&'a str>),
6    Http(String),
7    Json(serde_json::Error),
8    IO(std::io::Error),
9}
10
11impl<'a> From<getargs::Error<&'a str>> for MavenError<'a> {
12    fn from(err: getargs::Error<&'a str>) -> Self {
13        MavenError::Args(err)
14    }
15}
16
17impl From<ureq::Error> for MavenError<'_> {
18    fn from(err: ureq::Error) -> Self {
19        MavenError::Http(err.to_string())
20    }
21}
22
23impl From<serde_json::Error> for MavenError<'_> {
24    fn from(err: serde_json::Error) -> Self {
25        MavenError::Json(err)
26    }
27}
28
29impl From<std::io::Error> for MavenError<'_> {
30    fn from(err: std::io::Error) -> Self {
31        MavenError::IO(err)
32    }
33}
34
35pub type MavenResult<'a, T> = Result<T, MavenError<'a>>;
36
37#[derive(Clone, Debug, Default)]
38pub struct MavenSearchArgs<'a> {
39    pub show_version: bool,
40    pub show_help: bool,
41    pub format: &'a str,
42    pub search_term: Option<&'a str>,
43    pub check_for_update: bool,
44}
45
46#[derive(Debug, Deserialize)]
47pub struct LatestVersionInfo {
48    #[serde(default)]
49    pub version: String,
50}
51
52#[derive(Debug, Deserialize)]
53#[allow(non_snake_case)]
54pub struct Doc {
55    pub id: String,
56    pub namespace: String,
57    pub name: String,
58    pub latestVersionInfo: LatestVersionInfo,
59    pub version: Option<String>,
60}
61
62#[derive(Debug, Deserialize)]
63pub struct HttpResponse {
64    pub components: Vec<Doc>,
65}