pub struct Client(_);
Expand description
An aria2 websocket rpc client.
The client contains an Arc<InnerClient>)
and can be cloned.
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
sourceimpl Client
impl Client
sourcepub async fn connect(url: &str, token: Option<&str>) -> Result<Self, Error>
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();
}
pub async fn call(
&self,
id: u64,
method: &str,
params: Vec<Value>
) -> Result<(), Error>
sourcepub async fn call_and_subscribe<T: DeserializeOwned + Send>(
&self,
method: &str,
params: Vec<Value>,
timeout: Option<Duration>
) -> Result<T, Error>
pub async fn call_and_subscribe<T: DeserializeOwned + Send>(
&self,
method: &str,
params: Vec<Value>,
timeout: Option<Duration>
) -> Result<T, Error>
Call aria2 with the given method and params, and return the result in timeout.
If the timeout is None
, the default timeout will be used.
If the timeout is zero, there will be no timeout.
sourcepub async fn set_hooks(&self, gid: &str, hooks: Option<TaskHooks>)
pub async fn set_hooks(&self, gid: &str, hooks: Option<TaskHooks>)
Set hook for task with given gid.
pub fn subscribe_notifications(&self) -> Receiver<Notification>
sourceimpl Client
impl Client
pub async fn get_version(&self) -> Result<Version, Error>
pub async fn add_uri(
&self,
uris: Vec<String>,
options: Option<TaskOptions>,
position: Option<u32>,
hooks: Option<TaskHooks>
) -> Result<String, Error>
pub async fn add_torrent(
&self,
torrent: impl AsRef<[u8]>,
uris: Option<Vec<String>>,
options: Option<TaskOptions>,
position: Option<u32>,
hooks: Option<TaskHooks>
) -> Result<String, Error>
pub async fn add_metalink(
&self,
metalink: impl AsRef<[u8]>,
options: Option<TaskOptions>,
position: Option<u32>,
hooks: Option<TaskHooks>
) -> Result<String, Error>
pub async fn remove(&self, gid: &str) -> Result<(), Error>
pub async fn force_remove(&self, gid: &str) -> Result<(), Error>
pub async fn pause(&self, gid: &str) -> Result<(), Error>
pub async fn pause_all(&self) -> Result<(), Error>
pub async fn force_pause(&self, gid: &str) -> Result<(), Error>
pub async fn force_pause_all(&self) -> Result<(), Error>
pub async fn unpause(&self, gid: &str) -> Result<(), Error>
pub async fn unpause_all(&self) -> Result<(), Error>
pub async fn custom_tell_status(
&self,
gid: &str,
keys: Option<Vec<String>>
) -> Result<Map<String, Value>, Error>
pub async fn tell_status(&self, gid: &str) -> Result<Status, Error>
pub async fn get_uris(&self, gid: &str) -> Result<Vec<Uri>, Error>
pub async fn get_files(&self, gid: &str) -> Result<Vec<File>, Error>
pub async fn get_peers(&self, gid: &str) -> Result<Vec<Peer>, Error>
pub async fn get_servers(
&self,
gid: &str
) -> Result<Vec<GetServersResult>, Error>
pub async fn tell_active(&self) -> Result<Vec<Status>, Error>
pub async fn tell_waiting(
&self,
offset: i32,
num: i32
) -> Result<Vec<Status>, Error>
pub async fn tell_stopped(
&self,
offset: i32,
num: i32
) -> Result<Vec<Status>, Error>
pub async fn custom_tell_active(
&self,
keys: Option<Vec<String>>
) -> Result<Vec<Map<String, Value>>, Error>
pub async fn custom_tell_waiting(
&self,
offset: i32,
num: i32,
keys: Option<Vec<String>>
) -> Result<Vec<Map<String, Value>>, Error>
pub async fn custom_tell_stopped(
&self,
offset: i32,
num: i32,
keys: Option<Vec<String>>
) -> Result<Vec<Map<String, Value>>, Error>
pub async fn change_position(
&self,
gid: &str,
pos: i32,
how: PositionHow
) -> Result<i32, Error>
sourcepub 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>
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.
pub async fn get_option(&self, gid: &str) -> Result<TaskOptions, Error>
pub async fn change_option(
&self,
gid: &str,
options: TaskOptions
) -> Result<(), Error>
pub async fn get_global_option(&self) -> Result<TaskOptions, Error>
pub async fn change_global_option(
&self,
options: TaskOptions
) -> Result<(), Error>
pub async fn get_global_stat(&self) -> Result<GlobalStat, Error>
pub async fn purge_download_result(&self) -> Result<(), Error>
pub async fn remove_download_result(&self, gid: &str) -> Result<(), Error>
pub async fn get_session_info(&self) -> Result<SessionInfo, Error>
pub async fn shutdown(&self) -> Result<(), Error>
pub async fn force_shutdown(&self) -> Result<(), Error>
pub async fn save_session(&self) -> Result<(), Error>
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more