Using the dotenv crate

The dotenv crate allows you to set environment variables in a file called .env and join them with variables set in the traditional way. You don't need to read this file manually. All you need to do is add the dependency and call the initialization method of the crate.

Add this crate to the list of dependencies :

dotenv = "0.13"

Add the following imports to the main.rs file of the previous example to use the dotenv crate:

use dotenv::dotenv;
use std::env;

Initialize it with the dotenv function, which will try to find the .env file. It will return a Result with a path to this file. Call the ok method of the Result to ignore it if the file hasn't been found.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.114.19