Clash

Struct Clash 

Source
pub struct Clash { /* private fields */ }
Expand description

§Clash API

Use struct Clash for interacting with Clash RESTful API. For more information, check https://github.com/Dreamacro/clash/wiki/external-controller-API-reference###Proxies, or maybe just read source code of clash

Implementations§

Source§

impl Clash

Source

pub fn builder<S: Into<String>>(url: S) -> Result<ClashBuilder>

Source

pub fn new(url: Url) -> Self

Source

pub fn oneshot_req_with_body( &self, endpoint: &str, method: &str, body: Option<String>, ) -> Result<String>

Send a oneshot request to the specific endpoint with method, with body

Source

pub fn oneshot_req(&self, endpoint: &str, method: &str) -> Result<String>

Send a oneshot request to the specific endpoint with method, without body

Source

pub fn longhaul_req<T: DeserializeOwned>( &self, endpoint: &str, method: &str, ) -> Result<LongHaul<T>>

Send a longhaul request to the specific endpoint with method, Underlying is an http stream with chunked-encoding.

Use LongHaul::next_item, LongHaul::next_raw or Iterator::next to retreive data

§Examplel
let traffics = clash.longhaul_req::<Traffic>("traffic", "GET").expect("connect failed");

// LongHaul implements `Iterator` so you can use iterator combinators
for traffic in traffics.take(3) {
    println!("{:#?}", traffic)
}
Source

pub fn get<T: DeserializeOwned>(&self, endpoint: &str) -> Result<T>

Helper function for method GET

Source

pub fn delete(&self, endpoint: &str) -> Result<()>

Helper function for method DELETE

Source

pub fn put<T: DeserializeOwned>( &self, endpoint: &str, body: Option<String>, ) -> Result<T>

Helper function for method PUT

Source

pub fn get_version(&self) -> Result<Version>

Get clash version

Source

pub fn get_configs(&self) -> Result<Config>

Get base configs

Source

pub fn reload_configs(&self, force: bool, path: &str) -> Result<()>

Reloading base configs.

  • force: will change ports etc.,
  • path: the absolute path to config file

This will NOT affect external-controller & secret

Source

pub fn get_proxies(&self) -> Result<Proxies>

Get proxies information

Source

pub fn get_rules(&self) -> Result<Rules>

Get rules information

Source

pub fn get_proxy(&self, proxy: &str) -> Result<Proxy>

Get specific proxy information

Source

pub fn get_connections(&self) -> Result<Connections>

Get connections information

Source

pub fn close_connections(&self) -> Result<()>

Close all connections

Source

pub fn close_one_connection(&self, id: &str) -> Result<()>

Close specific connection

Source

pub fn get_traffic(&self) -> Result<LongHaul<Traffic>>

Get real-time traffic data

Note: This is a longhaul request, which will last forever until interrupted or disconnected.

See longhaul_req for more information

Source

pub fn get_log(&self) -> Result<LongHaul<Log>>

Get real-time logs

Note: This is a longhaul request, which will last forever until interrupted or disconnected.

See longhaul_req for more information

Source

pub fn get_proxy_delay( &self, proxy: &str, test_url: &str, timeout: u64, ) -> Result<Delay>

Get specific proxy delay test information

Source

pub fn set_proxygroup_selected(&self, group: &str, proxy: &str) -> Result<()>

Select specific proxy

Trait Implementations§

Source§

impl Clone for Clash

Source§

fn clone(&self) -> Clash

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Clash

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Clash

§

impl !RefUnwindSafe for Clash

§

impl Send for Clash

§

impl Sync for Clash

§

impl Unpin for Clash

§

impl !UnwindSafe for Clash

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,