Expand description
Formats strings by expanding variables, similar to shell expansion.
This crate provides a simple and efficient way to substitute variables in a
string, using either the process environment or a custom context like a
HashMap.
The main entry points are the format() and format_with() functions.
§Docs
- Overview
- Getting Started
- Use HashMap as Data Source
- Provide Default Values
- Escape a Dollar Sign
- Implement the Context Trait
§Examples
Using environment variables:
let formatted = envfmt::format("This package is $CARGO_PKG_NAME.").unwrap();
assert_eq!(formatted, "This package is envfmt.");Using a custom context:
use std::collections::HashMap;
let mut context = HashMap::new();
context.insert("thing", "world");
let input = "Hello, ${thing}!";
let result = envfmt::format_with(input, &context).unwrap();
assert_eq!(result, "Hello, world!");Enums§
- Error
- Represents errors that can occur during formatting.
Traits§
- Context
- A trait for providing values for variable expansion.
Functions§
- format
- Formats a string by expanding variables from the process environment.
- format_
with - Formats a string by expanding variables from a given context.