diff --git a/async_ex1/src/main.rs b/async_ex1/src/main.rs
index 7057e694..1bb4fd2d 100644
--- a/async_ex1/src/main.rs
+++ b/async_ex1/src/main.rs
@@ -12,7 +12,6 @@
// - POSTing json body
// 3. chaining futures into a single response used by an asynch endpoint
-
#[macro_use]
extern crate validator_derive;
#[macro_use]
@@ -47,8 +46,6 @@ struct HttpBinResponse {
url: String,
}
-
-
/// post json to httpbin, get it back in the response body, return deserialized
fn step_x(
data: SomeData,
@@ -93,12 +90,9 @@ fn main() -> io::Result<()> {
println!("Starting server at: {:?}", endpoint);
HttpServer::new(|| {
- App::new()
- .data(Client::default())
- .service(
- web::resource("/something")
- .route(web::post().to_async(create_something)),
- )
+ App::new().data(Client::default()).service(
+ web::resource("/something").route(web::post().to_async(create_something)),
+ )
})
.bind(endpoint)?
.run()
diff --git a/async_ex2/src/appconfig.rs b/async_ex2/src/appconfig.rs
index ae23b09c..e38629a6 100644
--- a/async_ex2/src/appconfig.rs
+++ b/async_ex2/src/appconfig.rs
@@ -1,47 +1,36 @@
use actix_web::{error, web};
-use bytes::Bytes;
-use futures::Stream;
-use crate::{
- handlers::{
- products,
- parts
- },
-};
+use crate::handlers::{parts, products};
-
-pub fn config_app
(cfg: &mut web::RouterConfig
)
- where P: Stream-
- + 'static
-{
+pub fn config_app(cfg: &mut web::RouterConfig) {
// domain includes: /products/{product_id}/parts/{part_id}
cfg.service(
web::scope("/products")
.service(
web::resource("")
.route(web::get().to_async(products::get_products))
- .route(web::post().to_async(products::add_product))
+ .route(web::post().to_async(products::add_product)),
)
.service(
web::scope("/{product_id}")
.service(
web::resource("")
.route(web::get().to_async(products::get_product_detail))
- .route(web::delete().to_async(products::remove_product))
+ .route(web::delete().to_async(products::remove_product)),
)
.service(
web::scope("/parts")
.service(
web::resource("")
.route(web::get().to_async(parts::get_parts))
- .route(web::post().to_async(parts::add_part))
+ .route(web::post().to_async(parts::add_part)),
)
.service(
web::resource("/{part_id}")
.route(web::get().to_async(parts::get_part_detail))
- .route(web::delete().to_async(parts::remove_part))
- )
- )
- )
+ .route(web::delete().to_async(parts::remove_part)),
+ ),
+ ),
+ ),
);
-}
\ No newline at end of file
+}
diff --git a/async_ex2/src/bin/main.rs b/async_ex2/src/bin/main.rs
index 44c9c7e7..f5ee4fb9 100644
--- a/async_ex2/src/bin/main.rs
+++ b/async_ex2/src/bin/main.rs
@@ -1,19 +1,16 @@
use actix_web::{middleware, App, HttpServer};
-use async_ex2::{
- appconfig::config_app,
-};
-
+use async_ex2::appconfig::config_app;
fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info");
env_logger::init();
- HttpServer::new(||
+ HttpServer::new(|| {
App::new()
.configure(config_app)
.wrap(middleware::Logger::default())
- )
+ })
.bind("127.0.0.1:8080")?
.run()
-}
\ No newline at end of file
+}
diff --git a/async_ex2/src/common.rs b/async_ex2/src/common.rs
index 4359c2ec..4c100617 100644
--- a/async_ex2/src/common.rs
+++ b/async_ex2/src/common.rs
@@ -1,6 +1,5 @@
use serde::{Deserialize, Serialize};
-
#[derive(Deserialize, Serialize)]
pub struct Product {
id: Option,
@@ -8,10 +7,9 @@ pub struct Product {
name: Option,
}
-
#[derive(Deserialize, Serialize)]
pub struct Part {
id: Option,
part_type: Option,
name: Option,
-}
\ No newline at end of file
+}
diff --git a/async_ex2/src/handlers/mod.rs b/async_ex2/src/handlers/mod.rs
index 17f9e2c2..299c561b 100644
--- a/async_ex2/src/handlers/mod.rs
+++ b/async_ex2/src/handlers/mod.rs
@@ -1,3 +1,2 @@
-pub mod products;
pub mod parts;
-
+pub mod products;
diff --git a/async_ex2/src/handlers/parts.rs b/async_ex2/src/handlers/parts.rs
index 22bb017a..0dba7b0f 100644
--- a/async_ex2/src/handlers/parts.rs
+++ b/async_ex2/src/handlers/parts.rs
@@ -1,26 +1,32 @@
-use actix_multipart::{Field, Item, Multipart, MultipartError};
-use actix_web::{HttpResponse, web, error, Error};
-use futures::{future::{ok as fut_ok, err as fut_err, Either}, Future, Stream};
+use actix_multipart::{Field, Multipart, MultipartError};
+use actix_web::{error, web, Error, HttpResponse};
+use futures::{
+ future::{err as fut_err, ok as fut_ok, Either},
+ Future, Stream,
+};
use crate::common::{Part, Product};
-
-pub fn get_parts(query: web::Query