Skip to content

Commit

Permalink
axum: Use str::parse instead of invoking FromStr directly
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte committed Mar 11, 2023
1 parent b5b9ffc commit a16120b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions frameworks/Rust/axum/src/database_pg_pool.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{io, str::FromStr};
use std::io;

use axum::{
async_trait,
Expand Down Expand Up @@ -33,8 +33,8 @@ pub async fn create_pool(
database_url: String,
max_pool_size: u32,
) -> deadpool_postgres::Pool {
let pg_config =
tokio_postgres::Config::from_str(&database_url).expect("invalid database url");
let pg_config: tokio_postgres::Config =
database_url.parse().expect("invalid database url");

let mgr_config = ManagerConfig {
recycling_method: RecyclingMethod::Fast,
Expand Down
9 changes: 4 additions & 5 deletions frameworks/Rust/axum/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ pub fn get_environment_variable<T: FromStr>(key: &str) -> T
where
<T as FromStr>::Err: Debug,
{
T::from_str(
&env::var(key)
.unwrap_or_else(|_| panic!("{} environment variable was not set", key)),
)
.unwrap_or_else(|_| panic!("could not parse {}", key))
env::var(key)
.unwrap_or_else(|_| panic!("{} environment variable was not set", key))
.parse::<T>()
.unwrap_or_else(|_| panic!("could not parse {}", key))
}

#[derive(Debug, Deserialize)]
Expand Down

0 comments on commit a16120b

Please sign in to comment.