fix clippy warnings

This commit is contained in:
mpostma 2021-03-15 16:52:05 +01:00
parent 01479dcf99
commit abbea59732
No known key found for this signature in database
GPG key ID: CBC8A7C1D7A28C3A
17 changed files with 124 additions and 131 deletions

View file

@ -105,7 +105,7 @@ async fn get_all_documents(
.attributes_to_retrieve
.as_ref()
.map(|attrs| attrs
.split(",")
.split(',')
.map(String::from)
.collect::<Vec<_>>());

View file

@ -37,13 +37,12 @@ async fn get_index(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
match data.index(&path.index_uid).await? {
Some(meta) => {
match data.index(path.index_uid.clone()).await {
Ok(meta) => {
let json = serde_json::to_string(&meta).unwrap();
Ok(HttpResponse::Ok().body(json))
}
None => {
let e = format!("Index {:?} doesn't exist.", path.index_uid);
Err(e) => {
Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
}
}
@ -61,7 +60,8 @@ async fn create_index(
data: web::Data<Data>,
body: web::Json<IndexCreateRequest>,
) -> Result<HttpResponse, ResponseError> {
match data.create_index(&body.uid, body.primary_key.clone()).await {
let body = body.into_inner();
match data.create_index(body.uid, body.primary_key).await {
Ok(meta) => {
let json = serde_json::to_string(&meta).unwrap();
Ok(HttpResponse::Ok().body(json))
@ -95,7 +95,8 @@ async fn update_index(
path: web::Path<IndexParam>,
body: web::Json<UpdateIndexRequest>,
) -> Result<HttpResponse, ResponseError> {
match data.update_index(&path.index_uid, body.primary_key.as_ref(), body.uid.as_ref()).await {
let body = body.into_inner();
match data.update_index(path.into_inner().index_uid, body.primary_key, body.uid).await {
Ok(meta) => {
let json = serde_json::to_string(&meta).unwrap();
Ok(HttpResponse::Ok().body(json))
@ -133,16 +134,13 @@ async fn get_update_status(
data: web::Data<Data>,
path: web::Path<UpdateParam>,
) -> Result<HttpResponse, ResponseError> {
let result = data.get_update_status(&path.index_uid, path.update_id).await;
let params = path.into_inner();
let result = data.get_update_status(params.index_uid, params.update_id).await;
match result {
Ok(Some(meta)) => {
Ok(meta) => {
let json = serde_json::to_string(&meta).unwrap();
Ok(HttpResponse::Ok().body(json))
}
Ok(None) => {
let e = format!("update {} for index {:?} doesn't exists.", path.update_id, path.index_uid);
Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
}
Err(e) => {
Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
}
@ -154,7 +152,7 @@ async fn get_all_updates_status(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
let result = data.get_updates_status(&path.index_uid).await;
let result = data.get_updates_status(path.into_inner().index_uid).await;
match result {
Ok(metas) => {
let json = serde_json::to_string(&metas).unwrap();

View file

@ -36,19 +36,19 @@ impl TryFrom<SearchQueryGet> for SearchQuery {
fn try_from(other: SearchQueryGet) -> anyhow::Result<Self> {
let attributes_to_retrieve = other
.attributes_to_retrieve
.map(|attrs| attrs.split(",").map(String::from).collect::<Vec<_>>());
.map(|attrs| attrs.split(',').map(String::from).collect::<Vec<_>>());
let attributes_to_crop = other
.attributes_to_crop
.map(|attrs| attrs.split(",").map(String::from).collect::<Vec<_>>());
.map(|attrs| attrs.split(',').map(String::from).collect::<Vec<_>>());
let attributes_to_highlight = other
.attributes_to_highlight
.map(|attrs| attrs.split(",").map(String::from).collect::<HashSet<_>>());
.map(|attrs| attrs.split(',').map(String::from).collect::<HashSet<_>>());
let facet_distributions = other
.facet_distributions
.map(|attrs| attrs.split(",").map(String::from).collect::<Vec<_>>());
.map(|attrs| attrs.split(',').map(String::from).collect::<Vec<_>>());
let facet_filters = match other.facet_filters {
Some(ref f) => Some(serde_json::from_str(f)?),
@ -83,7 +83,7 @@ async fn search_with_url_query(
return Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
}
};
let search_result = data.search(&path.index_uid, query).await;
let search_result = data.search(path.into_inner().index_uid, query).await;
match search_result {
Ok(docs) => {
let docs = serde_json::to_string(&docs).unwrap();
@ -101,7 +101,7 @@ async fn search_with_post(
path: web::Path<IndexParam>,
params: web::Json<SearchQuery>,
) -> Result<HttpResponse, ResponseError> {
let search_result = data.search(&path.index_uid, params.into_inner()).await;
let search_result = data.search(path.into_inner().index_uid, params.into_inner()).await;
match search_result {
Ok(docs) => {
let docs = serde_json::to_string(&docs).unwrap();

View file

@ -64,7 +64,7 @@ macro_rules! make_setting_route {
data: actix_web::web::Data<data::Data>,
index_uid: actix_web::web::Path<String>,
) -> std::result::Result<HttpResponse, ResponseError> {
match data.settings(index_uid.as_ref()).await {
match data.settings(index_uid.into_inner()).await {
Ok(settings) => {
let setting = settings.$attr;
let json = serde_json::to_string(&setting).unwrap();
@ -153,7 +153,7 @@ async fn get_all(
data: web::Data<Data>,
index_uid: web::Path<String>,
) -> Result<HttpResponse, ResponseError> {
match data.settings(index_uid.as_ref()).await {
match data.settings(index_uid.into_inner()).await {
Ok(settings) => {
let json = serde_json::to_string(&settings).unwrap();
Ok(HttpResponse::Ok().body(json))