Closed LeoniePhiline closed 1 year ago
For most of these, I prefer the original. See this comparison:
Original
dotenvy::from_filename("custom.env").unwrap();
Suggested
fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenvy::from_filename("custom.env")?;
Ok(())
}
The original is more legible for illustrating the usage of from_filename()
.
I can see ?
being preferable to unwrap()
in lengthier examples that are often copied and pasted, but that isn't usually the case here.
@allan2 You're missing here that rustdoc renders this as:
dotenvy::from_filename("custom.env")?;
The entire code block is being run as a test. Lines prefixed with #
are removed from user-facing documentation.
This is common practice, as well as best practice in Rust projects.
I would recommend you run cargo doc --open
and have a look at the generated documentation.
I can see ? being preferable to unwrap() in lengthier examples that are often copied and pasted, but that isn't usually the case here.
This isn't at all related to lengthiness, but about proliferating proper error handling.
I am very sure the examples shown in the dotenvy
documentation are copy-pasted very, very often.
My apologies, I did miss that.
This PR looks good to me!
This PR
Fixes #49
Notes
A note regarding the
from_path*
example changesI simplified these examples, as they did not plainly show off usage and were somewhat nonsensical:
.as_path()
for a method acceptingAsRef<Path>
, whichPathBuf
implements.from_filename*
andfrom_path*
(which is in fact the recursive lookup in parent directories). I'll open a separate issue about that to keep the PR clean.A note regarding
dotenv_override
example changesuse
by fully qualified name to keep consistent with the otherdotenv*
examples..ok()
for consistency with thedotenvy::dotenv
example.