proxyster_lib/
provider_source.rs

1use serde_derive::Deserialize;
2
3/**
4A proxy source
5
6# Examples
7
8(in `providers.toml`)
9
10```toml
11[[proxy]]
12name = "proxy1"
13sources = ["https://raw.githubusercontent.com/..."]
14```
15*/
16#[derive(Deserialize)]
17pub struct ProviderSource {
18    pub url: Option<String>,
19    pub selector: String,
20    pub regex: Option<String>,
21}
22
23// implement From for ProviderSource
24impl From<toml::Value> for ProviderSource {
25    fn from(value: toml::Value) -> Self {
26        ProviderSource {
27            url: value.get("url").map(|v| v.as_str().unwrap().to_owned()),
28            selector: value.get("selector").unwrap().as_str().unwrap().to_owned(),
29            regex: value.get("regex").map(|v| v.as_str().unwrap().to_owned()),
30        }
31    }
32}
33
34// implement Clone for ProviderSource
35impl Clone for ProviderSource {
36    fn clone(&self) -> Self {
37        ProviderSource {
38            url: self.url.clone(),
39            selector: self.selector.clone(),
40            regex: self.regex.clone(),
41        }
42    }
43}
44