#serialization #deserialize

serde-envfile

♻️ Deserialize and serialize environment variables

3 releases (breaking)

Uses new Rust 2024

0.3.0 May 27, 2025
0.2.0 Apr 4, 2025
0.1.0 Oct 27, 2023

#723 in Encoding

Download history 888/week @ 2025-11-05 468/week @ 2025-11-12 487/week @ 2025-11-19 658/week @ 2025-11-26 516/week @ 2025-12-03 392/week @ 2025-12-10 275/week @ 2025-12-17 374/week @ 2025-12-24 366/week @ 2025-12-31 546/week @ 2026-01-07 802/week @ 2026-01-14 673/week @ 2026-01-21 942/week @ 2026-01-28 856/week @ 2026-02-04 1106/week @ 2026-02-11 1378/week @ 2026-02-18

4,430 downloads per month
Used in 5 crates (4 directly)

MIT OR Apache-2.0 OR EUPL-1.2

45KB
1K SLoC

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).

Install

Extend your Cargo.toml configuration file to include serde-envfile as a dependency or install the package with the Cargo package manager.

cargo add serde-envfile

Example

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, 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(())
}

Dependencies

~0.4–1.2MB
~25K SLoC