Skip to content

Commit

Permalink
s/str::to_string/str::to_owned
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Jul 9, 2023
1 parent 9a5cd90 commit 8fd4262
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion auth/redis-session/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion auth/simple-auth-server/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl From<DBError> 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
Expand Down
2 changes: 1 addition & 1 deletion auth/simple-auth-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
16 changes: 8 additions & 8 deletions forms/form/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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();

Expand All @@ -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;
Expand All @@ -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::<actix_web::web::Data<AppState>>().unwrap();
let params = Form(MyParams {
name: "John".to_string(),
name: "John".to_owned(),
});
let resp = handle_post_2(data.clone(), params).await.unwrap();

Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion https-tls/openssl-auto-le/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
Expand Down
2 changes: 1 addition & 1 deletion json/json-error/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl ResponseError for Error {

async fn index() -> Result<HttpResponse, Error> {
Err(Error {
msg: "an example error message".to_string(),
msg: "an example error message".to_owned(),
status: 400,
})
}
Expand Down
7 changes: 2 additions & 5 deletions json/json-validation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use std::io;

use actix_web::{
error::ErrorBadRequest,
http::header::ContentType,
web::{self, BytesMut},
App, Error, HttpResponse, HttpServer,
};
Expand Down Expand Up @@ -56,7 +55,7 @@ async fn step_x(data: SomeData, client: &Client) -> actix_web::Result<SomeData>
body.extend_from_slice(&chunk?);
}

let body: HttpBinResponse = serde_json::from_slice(&body).unwrap();
let body = serde_json::from_slice::<HttpBinResponse>(&body).unwrap();

println!("{body:?}");

Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion server-sent-events/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
4 changes: 2 additions & 2 deletions templating/handlebars/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ fn get_error_response<B>(res: &ServiceResponse<B>, 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
Expand Down
2 changes: 1 addition & 1 deletion templating/sailfish/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn page(params: web::Path<(i32,)>) -> actix_web::Result<impl Responder> {

#[get("/")]
async fn hello() -> impl Responder {
Html("<p>Hello world!</p>".to_string())
Html("<p>Hello world!</p>".to_owned())
}

#[actix_web::main]
Expand Down
4 changes: 2 additions & 2 deletions templating/tera/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ fn get_error_response<B>(res: &ServiceResponse<B>, 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::<web::Data<Tera>>().map(|t| t.get_ref());
Expand Down
4 changes: 2 additions & 2 deletions templating/tinytemplate/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ fn get_error_response<B>(res: &ServiceResponse<B>, 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
Expand Down
2 changes: 1 addition & 1 deletion websockets/chat-broker/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Handler<JoinRoom> 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);
Expand Down
4 changes: 2 additions & 2 deletions websockets/chat-broker/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
);
Expand Down

0 comments on commit 8fd4262

Please sign in to comment.