r/rust • u/OptimalAnywhere6282 • 4d ago
🙋 seeking help & advice load shell variables from file
i need to read a file containing variables, which has the exact same format as a regular .env file (KEY="value")
the loadenv crate only reads $(pwd)/.env and does not accept custom paths (unless modified, which defeats the point of using a crate)
i won't ask AI
5
u/emetah850 4d ago
There is also the dotenvy crate, which I personally use for .env related projects
2
u/Fit-Reaction242 2d ago
dotenvy does custom paths, `dotenvy::from_path("/your/file")` loads it into the env and `from_path_iter` just gives you the pairs if you dont want them set
1
u/wyvernbw 3d ago
writing a function to do this would probably be less than 30 lines of code and its 0 dependencies
1
u/Fit-Reaction242 20h ago
dotenvy does custom paths, `dotenvy::from_path("/your/file")` loads it into the env and `from_path_iter` just gives you the pairs if you dont want them set
7
u/Solumin 4d ago
Load the file yourself and use
loadenv's load_buf function.