Skip to content

Commit

Permalink
give methods in client_helpers better type param names
Browse files Browse the repository at this point in the history
  • Loading branch information
wfraser committed Nov 5, 2024
1 parent df33123 commit 4f65877
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/client_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,21 @@ pub(crate) async fn body_to_string(body: &mut (dyn AsyncRead + Send + Unpin)) ->
/// etc.). The inner result has an error if the server returned one for the request, otherwise it
/// has the deserialized JSON response and the body stream (if any).
#[allow(clippy::too_many_arguments)]
pub async fn request_with_body<T, E, P, C>(
client: &C,
pub async fn request_with_body<TResponse, TError, TParams, TClient>(
client: &TClient,
endpoint: Endpoint,
style: Style,
function: &str,
params: &P,
params: &TParams,
body: Option<Body<'_>>,
range_start: Option<u64>,
range_end: Option<u64>,
) -> Result<HttpRequestResult<T>, Error<E>> where
T: DeserializeOwned,
E: DeserializeOwned + StdError,
P: Serialize,
C: HttpClient,
) -> Result<HttpRequestResult<TResponse>, Error<TError>>
where
TResponse: DeserializeOwned,
TError: DeserializeOwned + StdError,
TParams: Serialize,
TClient: HttpClient,
{
let mut retried = false;
'auth_retry: loop {
Expand Down Expand Up @@ -190,7 +191,7 @@ pub async fn request_with_body<T, E, P, C>(
if status == 409 {
// Response should be JSON-deseraializable into the strongly-typed
// error specified by type parameter E.
return match serde_json::from_str::<TopLevelError<E>>(&json) {
return match serde_json::from_str::<TopLevelError<TError>>(&json) {
Ok(deserialized) => {
error!("API error: {}", deserialized.error);
Err(Error::Api(deserialized.error))
Expand All @@ -214,7 +215,8 @@ pub async fn request_with_body<T, E, P, C>(
}

pub(crate) async fn parse_response(raw_resp: HttpRequestResultRaw, style: Style)
-> Result<(String, Option<u64>, Option<Box<dyn AsyncRead + Send + Unpin>>), Error> {
-> Result<(String, Option<u64>, Option<Box<dyn AsyncRead + Send + Unpin>>), Error>
{
let HttpRequestResultRaw {
status,
result_header,
Expand Down Expand Up @@ -320,14 +322,20 @@ impl<'a> From<&'a [u8]> for Body<'a> {
}
}

pub async fn request<T: DeserializeOwned, E: DeserializeOwned + StdError, P: Serialize>(
client: &impl HttpClient,
pub async fn request<TResponse, TError, TParams, TClient>(
client: &TClient,
endpoint: Endpoint,
style: Style,
function: &str,
params: &P,
params: &TParams,
body: Option<Body<'_>>,
) -> Result<T, Error<E>> {
) -> Result<TResponse, Error<TError>>
where
TResponse: DeserializeOwned,
TError: DeserializeOwned + StdError,
TParams: Serialize,
TClient: HttpClient,
{
request_with_body(client, endpoint, style, function, params, body, None, None)
.await
.map(|HttpRequestResult { result, .. }| result)
Expand Down

0 comments on commit 4f65877

Please sign in to comment.