diff --git a/auth/redis-session/src/main.rs b/auth/redis-session/src/main.rs index a60649b..259a17b 100644 --- a/auth/redis-session/src/main.rs +++ b/auth/redis-session/src/main.rs @@ -124,7 +124,7 @@ mod test { RedisActorSessionStore::new("127.0.0.1:6379"), private_key.clone(), ) - .cookie_name("test-session".to_string()) + .cookie_name("test-session".to_owned()) .build(), ) .wrap(middleware::Logger::default()) diff --git a/auth/simple-auth-server/src/errors.rs b/auth/simple-auth-server/src/errors.rs index 618154b..54c29d1 100644 --- a/auth/simple-auth-server/src/errors.rs +++ b/auth/simple-auth-server/src/errors.rs @@ -45,7 +45,7 @@ impl From for ServiceError { match error { DBError::DatabaseError(kind, info) => { if let DatabaseErrorKind::UniqueViolation = kind { - let message = info.details().unwrap_or_else(|| info.message()).to_string(); + let message = info.details().unwrap_or_else(|| info.message()).to_owned(); return ServiceError::BadRequest(message); } ServiceError::InternalServerError diff --git a/auth/simple-auth-server/src/main.rs b/auth/simple-auth-server/src/main.rs index 53d0e42..6f6a8a9 100644 --- a/auth/simple-auth-server/src/main.rs +++ b/auth/simple-auth-server/src/main.rs @@ -28,7 +28,7 @@ async fn main() -> std::io::Result<()> { let pool: models::Pool = r2d2::Pool::builder() .build(manager) .expect("Failed to create pool."); - let domain: String = std::env::var("DOMAIN").unwrap_or_else(|_| "localhost".to_string()); + let domain: String = std::env::var("DOMAIN").unwrap_or_else(|_| "localhost".to_owned()); log::info!("starting HTTP server at http://localhost:8080"); diff --git a/forms/form/src/main.rs b/forms/form/src/main.rs index 7329acb..c7a0c73 100644 --- a/forms/form/src/main.rs +++ b/forms/form/src/main.rs @@ -21,7 +21,7 @@ fn app_config(config: &mut web::ServiceConfig) { config.service( web::scope("") .app_data(web::Data::new(AppState { - foo: "bar".to_string(), + foo: "bar".to_owned(), })) .service(web::resource("/").route(web::get().to(index))) .service(web::resource("/post1").route(web::post().to(handle_post_1))) @@ -96,7 +96,7 @@ mod tests { #[actix_web::test] async fn handle_post_1_unit_test() { let params = Form(MyParams { - name: "John".to_string(), + name: "John".to_owned(), }); let resp = handle_post_1(params).await.unwrap(); @@ -116,7 +116,7 @@ mod tests { let req = test::TestRequest::post() .uri("/post1") .set_form(MyParams { - name: "John".to_string(), + name: "John".to_owned(), }) .to_request(); let resp: ServiceResponse = test::call_service(&app, req).await; @@ -134,12 +134,12 @@ mod tests { async fn handle_post_2_unit_test() { let state = TestRequest::default() .data(AppState { - foo: "bar".to_string(), + foo: "bar".to_owned(), }) .to_http_request(); let data = state.app_data::>().unwrap(); let params = Form(MyParams { - name: "John".to_string(), + name: "John".to_owned(), }); let resp = handle_post_2(data.clone(), params).await.unwrap(); @@ -161,7 +161,7 @@ mod tests { let req = test::TestRequest::post() .uri("/post2") .set_form(MyParams { - name: "John".to_string(), + name: "John".to_owned(), }) .to_request(); let resp: ServiceResponse = test::call_service(&app, req).await; @@ -183,7 +183,7 @@ mod tests { async fn handle_post_3_unit_test() { let req = TestRequest::default().to_http_request(); let params = Form(MyParams { - name: "John".to_string(), + name: "John".to_owned(), }); let result = handle_post_3(req.clone(), params).await; let resp = result.respond_to(&req); @@ -205,7 +205,7 @@ mod tests { let req = test::TestRequest::post() .uri("/post3") .set_form(MyParams { - name: "John".to_string(), + name: "John".to_owned(), }) .to_request(); let resp: ServiceResponse = test::call_service(&app, req).await; diff --git a/https-tls/openssl-auto-le/src/main.rs b/https-tls/openssl-auto-le/src/main.rs index bbb4be1..7291c50 100644 --- a/https-tls/openssl-auto-le/src/main.rs +++ b/https-tls/openssl-auto-le/src/main.rs @@ -14,7 +14,7 @@ pub async fn gen_tls_cert(user_email: &str, user_domain: &str) -> anyhow::Result // Create acme-challenge dir. fs::create_dir("./acme-challenge").unwrap(); - let domain = user_domain.to_string(); + let domain = user_domain.to_owned(); // Create temporary Actix Web server for ACME challenge. let srv = HttpServer::new(|| { diff --git a/json/json-error/src/main.rs b/json/json-error/src/main.rs index 3260d27..dda7c3a 100644 --- a/json/json-error/src/main.rs +++ b/json/json-error/src/main.rs @@ -31,7 +31,7 @@ impl ResponseError for Error { async fn index() -> Result { Err(Error { - msg: "an example error message".to_string(), + msg: "an example error message".to_owned(), status: 400, }) } diff --git a/json/json-validation/src/main.rs b/json/json-validation/src/main.rs index 0b55505..4df73d5 100644 --- a/json/json-validation/src/main.rs +++ b/json/json-validation/src/main.rs @@ -16,7 +16,6 @@ use std::io; use actix_web::{ error::ErrorBadRequest, - http::header::ContentType, web::{self, BytesMut}, App, Error, HttpResponse, HttpServer, }; @@ -56,7 +55,7 @@ async fn step_x(data: SomeData, client: &Client) -> actix_web::Result body.extend_from_slice(&chunk?); } - let body: HttpBinResponse = serde_json::from_slice(&body).unwrap(); + let body = serde_json::from_slice::(&body).unwrap(); println!("{body:?}"); @@ -71,9 +70,7 @@ async fn create_something( let some_data_3 = step_x(some_data_2, &client).await?; let d = step_x(some_data_3, &client).await?; - Ok(HttpResponse::Ok() - .content_type(ContentType::json()) - .body(serde_json::to_string(&d).unwrap())) + Ok(HttpResponse::Ok().json(d)) } #[actix_web::main] diff --git a/server-sent-events/src/main.rs b/server-sent-events/src/main.rs index e3c4f49..04ca420 100644 --- a/server-sent-events/src/main.rs +++ b/server-sent-events/src/main.rs @@ -30,7 +30,7 @@ async fn main() -> io::Result<()> { #[get("/")] async fn index() -> impl Responder { - Html(include_str!("index.html").to_string()) + Html(include_str!("index.html").to_owned()) } #[get("/events")] diff --git a/templating/handlebars/src/main.rs b/templating/handlebars/src/main.rs index 7b70ac0..3e4bb1b 100644 --- a/templating/handlebars/src/main.rs +++ b/templating/handlebars/src/main.rs @@ -77,10 +77,10 @@ fn get_error_response(res: &ServiceResponse, error: &str) -> HttpResponse< // Provide a fallback to a simple plain text response in case an error occurs during the // rendering of the error page. - let fallback = |e: &str| { + let fallback = |err: &str| { HttpResponse::build(res.status()) .content_type(ContentType::plaintext()) - .body(e.to_string()) + .body(err.to_string()) }; let hb = request diff --git a/templating/sailfish/src/main.rs b/templating/sailfish/src/main.rs index 4ab9c2c..a4e20c8 100644 --- a/templating/sailfish/src/main.rs +++ b/templating/sailfish/src/main.rs @@ -38,7 +38,7 @@ async fn page(params: web::Path<(i32,)>) -> actix_web::Result { #[get("/")] async fn hello() -> impl Responder { - Html("

Hello world!

".to_string()) + Html("

Hello world!

".to_owned()) } #[actix_web::main] diff --git a/templating/tera/src/main.rs b/templating/tera/src/main.rs index f9648bb..ef6e1d5 100644 --- a/templating/tera/src/main.rs +++ b/templating/tera/src/main.rs @@ -71,10 +71,10 @@ fn get_error_response(res: &ServiceResponse, error: &str) -> HttpResponse // Provide a fallback to a simple plain text response in case an error occurs during the // rendering of the error page. - let fallback = |e: &str| { + let fallback = |err: &str| { HttpResponse::build(res.status()) .content_type(ContentType::plaintext()) - .body(e.to_string()) + .body(err.to_string()) }; let tera = request.app_data::>().map(|t| t.get_ref()); diff --git a/templating/tinytemplate/src/main.rs b/templating/tinytemplate/src/main.rs index 06d2ba3..515de61 100644 --- a/templating/tinytemplate/src/main.rs +++ b/templating/tinytemplate/src/main.rs @@ -75,10 +75,10 @@ fn get_error_response(res: &ServiceResponse, error: &str) -> HttpResponse // Provide a fallback to a simple plain text response in case an error occurs during the // rendering of the error page. - let fallback = |e: &str| { + let fallback = |err: &str| { HttpResponse::build(res.status()) .content_type(ContentType::plaintext()) - .body(e.to_string()) + .body(err.to_string()) }; let tt = request diff --git a/websockets/chat-broker/src/server.rs b/websockets/chat-broker/src/server.rs index f09ed77..8908e6e 100644 --- a/websockets/chat-broker/src/server.rs +++ b/websockets/chat-broker/src/server.rs @@ -76,7 +76,7 @@ impl Handler for WsChatServer { let id = self.add_client_to_room(&room_name, None, client); let join_msg = format!( "{} joined {room_name}", - client_name.unwrap_or_else(|| "anon".to_string()), + client_name.unwrap_or_else(|| "anon".to_owned()), ); self.send_chat_message(&room_name, &join_msg, id); diff --git a/websockets/chat-broker/src/session.rs b/websockets/chat-broker/src/session.rs index 5755254..ae9d483 100644 --- a/websockets/chat-broker/src/session.rs +++ b/websockets/chat-broker/src/session.rs @@ -64,7 +64,7 @@ impl WsChatSession { pub fn send_msg(&self, msg: &str) { let content = format!( "{}: {msg}", - self.name.clone().unwrap_or_else(|| "anon".to_string()), + self.name.clone().unwrap_or_else(|| "anon".to_owned()), ); let msg = SendMessage(self.room.clone(), self.id, content); @@ -84,7 +84,7 @@ impl Actor for WsChatSession { fn stopped(&mut self, _ctx: &mut Self::Context) { log::info!( "WsChatSession closed for {}({}) in room {}", - self.name.clone().unwrap_or_else(|| "anon".to_string()), + self.name.clone().unwrap_or_else(|| "anon".to_owned()), self.id, self.room );