How to make dotenv crate override default shell variables

Let say i have this test function, my dotenv work fine except for the username variable. it keeps pulling my shell USERNAME variable.

my question is how do i make .env override the shell variable

    async fn test_function() {

        let host = env::var("HOST").unwrap();
        let port = env::var("PORT").unwrap();
        let username = env::var("USERNAME").unwrap();   // <- does not read from the .env file
        let password = env::var("PASSWORD").unwrap();

Seems like you can't.

There are a couple other issues/PRs, but as of now there is no API to do what you want as far as I can tell. If you control the .env file I would recommend prefixing the keys with the name of your program or something like that to avoid conflicts.

@Heliozoa your reply helped me out. following your link i found a pull request with a solution

for now i am using this

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.