Client

Struct Client 

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

An aria2 websocket rpc client.

§Example

use aria2_ws::Client;

#[tokio::main]
async fn main() {
    let client = Client::connect("ws://127.0.0.1:6800/jsonrpc", None)
        .await
        .unwrap();
    let version = client.get_version().await.unwrap();
    println!("{:?}", version);
}

Implementations§

Source§

impl Client

Source

pub async fn connect(url: &str, token: Option<&str>) -> Result<Self, Error>

Create a new Client that connects to the given url.

§Example
use aria2_ws::Client;

#[tokio::main]
async fn main() {
    let client = Client::connect("ws://127.0.0.1:6800/jsonrpc", None)
        .await
        .unwrap();
    let gid = client
        .add_uri(
            vec!["https://go.dev/dl/go1.17.6.windows-amd64.msi".to_string()],
            None,
            None,
            None,
        )
        .await
        .unwrap();
    client.force_remove(&gid).await.unwrap();
}
Source§

impl Client

Source

pub async fn add_uri( &self, uris: Vec<String>, options: Option<TaskOptions>, position: Option<u32>, callbacks: Option<Callbacks>, ) -> Result<String, Error>

Source

pub async fn add_torrent( &self, torrent: impl AsRef<[u8]>, uris: Option<Vec<String>>, options: Option<TaskOptions>, position: Option<u32>, callbacks: Option<Callbacks>, ) -> Result<String, Error>

Methods from Deref<Target = InnerClient>§

Source

pub async fn call( &self, id: i32, method: &str, params: Vec<Value>, ) -> Result<(), Error>

Send a rpc request to websocket without waiting for response.

Source

pub async fn call_and_wait<T>( &self, method: &str, params: Vec<Value>, ) -> Result<T, Error>

Send a rpc request to websocket and wait for corresponding response.

Source

pub fn subscribe_notifications(&self) -> Receiver<Notification>

Subscribe to notifications.

Returns a instance of broadcast::Receiver which can be used to receive notifications.

Source

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

Source

pub async fn remove(&self, gid: &str) -> Result<(), Error>

Source

pub async fn force_remove(&self, gid: &str) -> Result<(), Error>

Source

pub async fn pause(&self, gid: &str) -> Result<(), Error>

Source

pub async fn pause_all(&self) -> Result<(), Error>

Source

pub async fn force_pause(&self, gid: &str) -> Result<(), Error>

Source

pub async fn force_pause_all(&self) -> Result<(), Error>

Source

pub async fn unpause(&self, gid: &str) -> Result<(), Error>

Source

pub async fn unpause_all(&self) -> Result<(), Error>

Source

pub async fn custom_tell_status( &self, gid: &str, keys: Option<Vec<String>>, ) -> Result<Map<String, Value>, Error>

Source

pub async fn tell_status(&self, gid: &str) -> Result<Status, Error>

Source

pub async fn get_uris(&self, gid: &str) -> Result<Vec<Uri>, Error>

Source

pub async fn get_files(&self, gid: &str) -> Result<Vec<File>, Error>

Source

pub async fn get_peers(&self, gid: &str) -> Result<Vec<Peer>, Error>

Source

pub async fn get_servers( &self, gid: &str, ) -> Result<Vec<GetServersResult>, Error>

Source

pub async fn tell_active(&self) -> Result<Vec<Status>, Error>

Source

pub async fn tell_waiting( &self, offset: i32, num: i32, ) -> Result<Vec<Status>, Error>

Source

pub async fn tell_stopped( &self, offset: i32, num: i32, ) -> Result<Vec<Status>, Error>

Source

pub async fn custom_tell_active( &self, keys: Option<Vec<String>>, ) -> Result<Vec<Map<String, Value>>, Error>

Source

pub async fn custom_tell_waiting( &self, offset: i32, num: i32, keys: Option<Vec<String>>, ) -> Result<Vec<Map<String, Value>>, Error>

Source

pub async fn custom_tell_stopped( &self, offset: i32, num: i32, keys: Option<Vec<String>>, ) -> Result<Vec<Map<String, Value>>, Error>

Source

pub async fn change_position( &self, gid: &str, pos: i32, how: PositionHow, ) -> Result<i32, Error>

Source

pub async fn change_uri( &self, gid: &str, file_index: i32, del_uris: Vec<String>, add_uris: Vec<String>, position: Option<i32>, ) -> Result<(i32, i32), Error>

§Returns

This method returns a list which contains two integers.

The first integer is the number of URIs deleted. The second integer is the number of URIs added.

Source

pub async fn get_option(&self, gid: &str) -> Result<TaskOptions, Error>

Source

pub async fn change_option( &self, gid: &str, options: TaskOptions, ) -> Result<(), Error>

Source

pub async fn get_global_option(&self) -> Result<TaskOptions, Error>

Source

pub async fn change_global_option( &self, options: TaskOptions, ) -> Result<(), Error>

Source

pub async fn get_global_stat(&self) -> Result<GlobalStat, Error>

Source

pub async fn purge_download_result(&self) -> Result<(), Error>

Source

pub async fn remove_download_result(&self, gid: &str) -> Result<(), Error>

Source

pub async fn get_session_info(&self) -> Result<SessionInfo, Error>

Source

pub async fn shutdown(&self) -> Result<(), Error>

Source

pub async fn force_shutdown(&self) -> Result<(), Error>

Source

pub async fn save_session(&self) -> Result<(), Error>

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

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 Deref for Client

Source§

type Target = InnerClient

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V