sub-converter (library)
Core library for converting subscription inputs (Clash YAML, SingBox JSON, and URI lists like ss://, trojan://) into Clash or SingBox configurations with optional templates.
Public API (stable surface)
- Types
InputFormat,OutputFormat,InputItemtemplate::Template(Template::Clash(ClashConfig),Template::SingBox(SingBoxConfig))formats::{ClashConfig, SingBoxConfig}Error,Result
- Functions
detect_format(content: &str) -> Result<InputFormat>convert(inputs: Vec<InputItem>, template: Template) -> Result<String>
Internal modules (parsing, emitting, IR) are intentionally not exposed to avoid abstraction leakage.
Quick start
use ;
use Template;
use ;
Multiple inputs and merging
convert accepts multiple InputItems (mixed formats). Items are parsed then merged in order.
let inputs = vec!;
let out = convert?;
Templates
Use defaults via ClashConfig::default() / SingBoxConfig::default(), or build from serde:
let tpl_yaml: &str = include_str!;
let clash_tpl: ClashConfig = from_str?;
let out = convert?;
Error handling
All operations return Result<T, Error>, covering validation, parsing, emitting, and template errors.
Design
- Minimal, stable façade: high-level
detect_format+convert - Strong typing for templates via
ClashConfig/SingBoxConfig - Internals remain private to prevent coupling