#env-var #environment #upper-case #case-insensitive #lower-case #env

kasedenv

Read environment variables by lower, upper case or case-insensitive keys

1 unstable release

0.1.0 Feb 23, 2024

#607 in Text processing

BSD-3-Clause

7KB
118 lines

kasedenv

[Crates.io Version(https://img.shields.io/crates/v/kasedenv?style=for-the-badge&logo=rust)] [docs.rs(https://img.shields.io/docsrs/sqlx?style=for-the-badge&logo=docs.rs)]

Read environment variables by lower, upper case or case-insensitive keys.

Unicode support for keys (comparing regardless of case) is enabled through the unicode feature.

[source,rust]

use unkasedenv::{uncased_var, lower_var, upper_var};

env::set_var("HeLlO", "world");
assert_eq!(uncased_var("Hello"), Ok("world".to_string()));
assert_eq!(lower_var("hello"), Ok("world".to_string()));
assert_eq!(upper_var("HELLO"), Ok("world".to_string()));

/* with `unicode` feature enabled */
env::set_var("Maße", "42");
assert_eq!(uncased_var("mAßE"), Ok("42".to_string()));
assert_eq!(lower_var("maße"), Ok("42".to_string()));
assert_eq!(upper_var("MASSE"), Ok("42".to_string()));

lib.rs:

Read environment variables by lower, upper case or case-insensitive keys

  • This crate provides an interface similar to std::env but whose keys are
  • converted to lower or UPPER case, or presented in a way that can be compared
  • regardless of case, either ASCII or Unicode (with feature unicode enabled,
  • using unicase).
  • Only variants of env::var and env::vars are provided, since OsStrs
  • are not necessarily human-readable character strings.

Dependencies

~24KB