diesel-rs / diesel

A safe, extensible ORM and Query Builder for Rust
https://diesel.rs
Apache License 2.0
12.74k stars 1.07k forks source link

First Rust example code on the website is unidiomatic #2451

Open jplatte opened 4 years ago

jplatte commented 4 years ago

The first Rust code example, also available under examples/postgres/getting_started_step_1, is using .ok(); to discard the error case of a Result. If ignoring any errors is intentional, that line should be updated from

dotenv().ok();

to

let _ = dotenv();

Otherwise, the .ok() should be replaced by something else (maybe .expect("dotenv setup to be successful")).

Checklist

weiznich commented 4 years ago

Can you submit a PR changing the corresponding code here?

jplatte commented 4 years ago

@weiznich I don't know what the intended behaviour is. Is it usually fatal if dotenv() setup fails or should a failure be ignored?

weiznich commented 4 years ago

First of all: I'm also not sure what's the intended behavior there, for error cases, as I've not written that code. Beside of that the documentation of dotenv uses literally the same code so I would say it's fine.

As far as I understand those snippet it just looks for a file called .env and loads it's content as environment variables. As it is doing io there are many reasons this call can fail, so it returns an error. For applications that normally non-fatal as if this load fails a few environment variables are not set.

jplatte commented 4 years ago

I guess I need to start with a PR on dotenv then.. Will do that soon.

PR open: https://github.com/dotenv-rs/dotenv/pull/57