I am using the Diesel ORM wrapper with PostgreSQL. I was following the guide on their website which has the following code:
pub fn establish_connection() -> PgConnection {
dotenv().ok();
let database_url = env::var("DATABASE_URL")
.expect("DATABASE_URL must be set");
PgConnection::establish(&database_url)
.expect(&format!("Error connecting to {}", database_url))
}
I understood what dotenv()
does through the dotenv docs — it loads the env file. In the source code I saw that that dotenv()
returns a Result
. What does ok()
do then? Does it unwrap the result? If so, why not use unwrap()
?