vsock_client: remove some &mut restrictions and rustfmt

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
Stefan Reiter 2021-03-31 12:21:45 +02:00 committed by Thomas Lamprecht
parent cab92acb3c
commit 971bc6f94b

View File

@ -12,7 +12,7 @@ use hyper::client::Client;
use hyper::Body; use hyper::Body;
use pin_project::pin_project; use pin_project::pin_project;
use serde_json::Value; use serde_json::Value;
use tokio::io::{ReadBuf, AsyncRead, AsyncWrite, AsyncWriteExt}; use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, ReadBuf};
use tokio::net::UnixStream; use tokio::net::UnixStream;
use crate::tools; use crate::tools;
@ -151,13 +151,13 @@ impl VsockClient {
self.api_request(req).await self.api_request(req).await
} }
pub async fn post(&mut self, path: &str, data: Option<Value>) -> Result<Value, Error> { pub async fn post(&self, path: &str, data: Option<Value>) -> Result<Value, Error> {
let req = Self::request_builder(self.cid, self.port, "POST", path, data)?; let req = Self::request_builder(self.cid, self.port, "POST", path, data)?;
self.api_request(req).await self.api_request(req).await
} }
pub async fn download( pub async fn download(
&mut self, &self,
path: &str, path: &str,
data: Option<Value>, data: Option<Value>,
output: &mut (dyn AsyncWrite + Send + Unpin), output: &mut (dyn AsyncWrite + Send + Unpin),
@ -166,14 +166,13 @@ impl VsockClient {
let client = self.client.clone(); let client = self.client.clone();
let resp = client.request(req) let resp = client
.request(req)
.await .await
.map_err(|_| format_err!("vsock download request timed out"))?; .map_err(|_| format_err!("vsock download request timed out"))?;
let status = resp.status(); let status = resp.status();
if !status.is_success() { if !status.is_success() {
Self::api_response(resp) Self::api_response(resp).await.map(|_| ())?
.await
.map(|_| ())?
} else { } else {
resp.into_body() resp.into_body()
.map_err(Error::from) .map_err(Error::from)