Skip to content

Commit

Permalink
Make request body structs and methods public for external access
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed Nov 5, 2024
1 parent 24fc543 commit abf9025
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tardis/src/web/web_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ where
}

/// Plain text body for [`TardisWebClient`],
pub struct PlainText<T>(T);
pub struct PlainText<T>(pub T);

/// Json body for [`TardisWebClient`],
pub struct Json<'a, T>(&'a T);
pub struct Json<'a, T>(pub &'a T);

impl<T: Into<String>> TardisRequestBody for PlainText<T> {
fn apply_on(self, builder: RequestBuilder) -> RequestBuilder {
Expand Down Expand Up @@ -319,14 +319,14 @@ impl TardisWebClient {
Ok((code, headers, response))
}

async fn to_text(&self, code: u16, headers: HashMap<String, String>, response: Response) -> TardisResult<TardisHttpResponse<String>> {
pub async fn to_text(&self, code: u16, headers: HashMap<String, String>, response: Response) -> TardisResult<TardisHttpResponse<String>> {
match response.text().await {
Ok(body) => Ok(TardisHttpResponse { code, headers, body: Some(body) }),
Err(error) => Err(TardisError::format_error(&format!("[Tardis.WebClient] {error:?}"), "406-tardis-webclient-text-error")),
}
}

async fn to_json<T: for<'de> Deserialize<'de>>(&self, code: u16, headers: HashMap<String, String>, response: Response) -> TardisResult<TardisHttpResponse<T>> {
pub async fn to_json<T: for<'de> Deserialize<'de>>(&self, code: u16, headers: HashMap<String, String>, response: Response) -> TardisResult<TardisHttpResponse<T>> {
match response.json().await {
Ok(body) => Ok(TardisHttpResponse { code, headers, body: Some(body) }),
Err(error) => Err(TardisError::format_error(&format!("[Tardis.WebClient] {error:?}"), "406-tardis-webclient-json-error")),
Expand Down

0 comments on commit abf9025

Please sign in to comment.