Expand description
§serde-envfile
Built ontop the dotenvy and
envy crates, serde-envfile
supports both the serialization and the deserialization of environment
variables from or to files (from_file, to_file), strings
(from_str, to_string), or the environment of the application
(from_env).
§Examples
Note that keys are transformed to lowercase during deserialization. With serialization, the contrary is the case.
use serde::{Deserialize, Serialize};
use serde_envfile::{Error, from_str, to_string};
#[derive(Debug, Deserialize, Serialize)]
struct Test {
hello: String,
}
fn main() -> Result<(), Error> {
let env = "HELLO=\"WORLD\"";
let test: Test = from_str(env)?;
let env = to_string(&test)?;
println!("{}", env);
Ok(())
}Introducing the Value type, serde-envfile, also provides a more flexible approach to working with environment variables.
use serde_envfile::{to_string, Error, Value};
fn main() -> Result<(), Error> {
let mut env = Value::new();
env.insert("hello".into(), "world".into());
let env = to_string(&env)?;
println!("{}", env);
Ok(())
}Structs§
- Prefixed
- Helper structure to work with prefixed environment variables more efficiently.
- Serializer
- A serializer to transform Rust data into environment variables.
- Value
- Flexible representation of environment variables.
Enums§
- Error
- Possible errors.
Functions§
- from_
env - Deserialize program-available environment variables into an instance of type
T. - from_
file - Deserialize an environment variable file into an instance of type
T. - from_
reader - Deserialize environment variables from a reader into an instance of type
T. - from_
str - Deserialize environment variables from a string into an instance of type
T. - prefixed
- Instantiates
Prefixedfrom which values can be both serialized and deserialized with a prefix. - to_file
- Serialize data into an environment variable file.
- to_
string - Serialize data into an environment variable string.
- to_
writer - Serialize data to a writer that implements
std::io::Write.