sub_converter/parse/
clash.rs1use crate::error::{Error, Result};
2use crate::formats::ClashConfig;
3use crate::ir::Node;
4
5pub struct ClashParser;
6
7impl super::Parser for ClashParser {
8 fn parse(&self, input: &str) -> Result<Vec<Node>> {
9 let input_trim = input.trim_start();
10 let cfg: ClashConfig = if input_trim.starts_with('{') {
11 let v: serde_yaml::Value =
12 serde_json::from_str(input).map_err(|e| Error::ParseError {
13 detail: format!("clash json: {e}"),
14 })?;
15 serde_yaml::from_value(v).map_err(|e| Error::ParseError {
16 detail: format!("clash json->yaml: {e}"),
17 })?
18 } else {
19 serde_yaml::from_str(input).map_err(|e| Error::ParseError {
20 detail: format!("clash yaml: {e}"),
21 })?
22 };
23 Ok(cfg.proxies.into_iter().map(Into::into).collect())
24 }
25}