Skip to content

Commit

Permalink
Apply Rust pre-commit hooks (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevino authored Jun 17, 2024
1 parent f33ce6c commit 4ca76b6
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 60 deletions.
6 changes: 1 addition & 5 deletions tokenization-client/src/apis/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1.0
*
*
* Generated by: https://openapi-generator.tech
*/



#[derive(Debug, Clone)]
pub struct Configuration {
pub base_path: String,
Expand All @@ -30,7 +28,6 @@ pub struct ApiKey {
pub key: String,
}


impl Configuration {
pub fn new() -> Configuration {
Configuration::default()
Expand All @@ -47,7 +44,6 @@ impl Default for Configuration {
oauth_access_token: None,
bearer_access_token: None,
api_key: None,

}
}
}
53 changes: 36 additions & 17 deletions tokenization-client/src/apis/default_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1.0
*
*
* Generated by: https://openapi-generator.tech
*/


use reqwest;

use super::{configuration, Error};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};


/// struct for typed errors of method [`handler_api_v1_task_tokenization_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -29,17 +27,25 @@ pub enum HealthCheckHealthGetError {
UnknownValue(serde_json::Value),
}


pub async fn handler_api_v1_task_tokenization_post(configuration: &configuration::Configuration, inputs: &str, model_id: &str) -> Result<models::TokenizationResults, Error<HandlerApiV1TaskTokenizationPostError>> {
pub async fn handler_api_v1_task_tokenization_post(
configuration: &configuration::Configuration,
inputs: &str,
model_id: &str,
) -> Result<models::TokenizationResults, Error<HandlerApiV1TaskTokenizationPostError>> {
let local_var_configuration = configuration;

let local_var_client = &local_var_configuration.client;

let local_var_uri_str = format!("{}/api/v1/task/tokenization", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
let local_var_uri_str = format!(
"{}/api/v1/task/tokenization",
local_var_configuration.base_path
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
let mut local_var_form = reqwest::multipart::Form::new();
local_var_form = local_var_form.text("inputs", inputs.to_string());
Expand All @@ -55,22 +61,31 @@ pub async fn handler_api_v1_task_tokenization_post(configuration: &configuration
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<HandlerApiV1TaskTokenizationPostError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
let local_var_entity: Option<HandlerApiV1TaskTokenizationPostError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}

pub async fn health_check_health_get(configuration: &configuration::Configuration, ) -> Result<String, Error<HealthCheckHealthGetError>> {
pub async fn health_check_health_get(
configuration: &configuration::Configuration,
) -> Result<String, Error<HealthCheckHealthGetError>> {
let local_var_configuration = configuration;

let local_var_client = &local_var_configuration.client;

let local_var_uri_str = format!("{}/health", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}

let local_var_req = local_var_req_builder.build()?;
Expand All @@ -82,9 +97,13 @@ pub async fn health_check_health_get(configuration: &configuration::Configuratio
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<HealthCheckHealthGetError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
let local_var_entity: Option<HealthCheckHealthGetError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}

16 changes: 9 additions & 7 deletions tokenization-client/src/apis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum Error<T> {
ResponseError(ResponseContent<T>),
}

impl <T> fmt::Display for Error<T> {
impl<T> fmt::Display for Error<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (module, e) = match self {
Error::Reqwest(e) => ("reqwest", e.to_string()),
Expand All @@ -28,7 +28,7 @@ impl <T> fmt::Display for Error<T> {
}
}

impl <T: fmt::Debug> error::Error for Error<T> {
impl<T: fmt::Debug> error::Error for Error<T> {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
Some(match self {
Error::Reqwest(e) => e,
Expand All @@ -39,19 +39,19 @@ impl <T: fmt::Debug> error::Error for Error<T> {
}
}

impl <T> From<reqwest::Error> for Error<T> {
impl<T> From<reqwest::Error> for Error<T> {
fn from(e: reqwest::Error) -> Self {
Error::Reqwest(e)
}
}

impl <T> From<serde_json::Error> for Error<T> {
impl<T> From<serde_json::Error> for Error<T> {
fn from(e: serde_json::Error) -> Self {
Error::Serde(e)
}
}

impl <T> From<std::io::Error> for Error<T> {
impl<T> From<std::io::Error> for Error<T> {
fn from(e: std::io::Error) -> Self {
Error::Io(e)
}
Expand All @@ -78,8 +78,10 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String
value,
));
}
},
serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())),
}
serde_json::Value::String(s) => {
params.push((format!("{}[{}]", prefix, key), s.clone()))
}
_ => params.push((format!("{}[{}]", prefix, key), value.to_string())),
}
}
Expand Down
2 changes: 1 addition & 1 deletion tokenization-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#[macro_use]
extern crate serde_derive;

extern crate reqwest;
extern crate serde;
extern crate serde_json;
extern crate url;
extern crate reqwest;

pub mod apis;
pub mod models;
7 changes: 2 additions & 5 deletions tokenization-client/src/models/http_validation_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1.0
*
*
* Generated by: https://openapi-generator.tech
*/

Expand All @@ -18,9 +18,6 @@ pub struct HttpValidationError {

impl HttpValidationError {
pub fn new() -> HttpValidationError {
HttpValidationError {
detail: None,
}
HttpValidationError { detail: None }
}
}

9 changes: 3 additions & 6 deletions tokenization-client/src/models/location_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1.0
*
*
* Generated by: https://openapi-generator.tech
*/

use crate::models;

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct LocationInner {
}
pub struct LocationInner {}

impl LocationInner {
pub fn new() -> LocationInner {
LocationInner {
}
LocationInner {}
}
}

3 changes: 1 addition & 2 deletions tokenization-client/src/models/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1.0
*
*
* Generated by: https://openapi-generator.tech
*/

Expand All @@ -29,4 +29,3 @@ impl Token {
}
}
}

17 changes: 13 additions & 4 deletions tokenization-client/src/models/tokenization_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1.0
*
*
* Generated by: https://openapi-generator.tech
*/

use crate::models;

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct TokenizationResults {
#[serde(rename = "results", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
#[serde(
rename = "results",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub results: Option<Option<Vec<models::Token>>>,
#[serde(rename = "token_count", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
#[serde(
rename = "token_count",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub token_count: Option<Option<i32>>,
}

Expand All @@ -26,4 +36,3 @@ impl TokenizationResults {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1.0
*
*
* Generated by: https://openapi-generator.tech
*/

Expand All @@ -20,10 +20,6 @@ pub struct TokenizationTaskHttpRequest1 {

impl TokenizationTaskHttpRequest1 {
pub fn new(inputs: String, model_id: String) -> TokenizationTaskHttpRequest1 {
TokenizationTaskHttpRequest1 {
inputs,
model_id,
}
TokenizationTaskHttpRequest1 { inputs, model_id }
}
}

9 changes: 2 additions & 7 deletions tokenization-client/src/models/validation_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1.0
*
*
* Generated by: https://openapi-generator.tech
*/

Expand All @@ -22,11 +22,6 @@ pub struct ValidationError {

impl ValidationError {
pub fn new(loc: Vec<models::LocationInner>, msg: String, r#type: String) -> ValidationError {
ValidationError {
loc,
msg,
r#type,
}
ValidationError { loc, msg, r#type }
}
}

0 comments on commit 4ca76b6

Please sign in to comment.