Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First Rust example code on the website is unidiomatic #2451

Open
2 tasks done
jplatte opened this issue Jul 6, 2020 · 4 comments
Open
2 tasks done

First Rust example code on the website is unidiomatic #2451

jplatte opened this issue Jul 6, 2020 · 4 comments

Comments

@jplatte
Copy link
Contributor

jplatte commented Jul 6, 2020

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

  • I have already looked over the issue tracker for similar issues.
  • This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)
    N/A
@weiznich
Copy link
Member

weiznich commented Jul 6, 2020

Can you submit a PR changing the corresponding code here?

@jplatte
Copy link
Contributor Author

jplatte commented Jul 6, 2020

@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
Copy link
Member

weiznich commented Jul 6, 2020

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
Copy link
Contributor Author

jplatte commented Jul 6, 2020

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

PR open: dotenv-rs/dotenv#57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants