1#![allow(clippy::doc_lazy_continuation)]
4
5use anyhow::anyhow;
6use std::{result::Result as StdResult, str::FromStr};
7
8pub mod chunk;
9pub mod error;
10pub mod types;
11
12pub mod proto {
13 include!(concat!(env!("OUT_DIR"), "/hipcheck.v1.rs"));
14}
15
16pub struct QueryTarget {
17 pub publisher: String,
18 pub plugin: String,
19 pub query: Option<String>,
20}
21
22impl FromStr for QueryTarget {
23 type Err = anyhow::Error;
24
25 fn from_str(s: &str) -> StdResult<Self, Self::Err> {
26 let parts: Vec<&str> = s.split('/').collect();
27 match parts.as_slice() {
28 [publisher, plugin, query] => Ok(Self {
29 publisher: publisher.to_string(),
30 plugin: plugin.to_string(),
31 query: Some(query.to_string()),
32 }),
33 [publisher, plugin] => Ok(Self {
34 publisher: publisher.to_string(),
35 plugin: plugin.to_string(),
36 query: None,
37 }),
38 _ => Err(anyhow!("Invalid query target string '{}'", s)),
39 }
40 }
41}
42
43impl TryInto<QueryTarget> for &str {
44 type Error = anyhow::Error;
45 fn try_into(self) -> StdResult<QueryTarget, Self::Error> {
46 QueryTarget::from_str(self)
47 }
48}