Skip to content

Commit

Permalink
Update README for new feature flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
de-vri-es committed Sep 15, 2024
1 parent b8a16e8 commit 656f21c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [change][patch] Update README for new feature flags.

# Version 0.3.4 - 2024-09-15
- [add][minor] Add optional support for the `indexmap` crate.

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ Shell-like variable substitution for strings and byte strings.

* Perform substitution in `&str` or in `&[u8]`.
* Provide a custom map of variables or use environment variables.
* Support for `indexmap` (requires the `indexmap` feature).
* Short format: `"Hello $name!"`
* Long format: `"Hello ${name}!"`
* Default values: `"Hello ${name:person}!"`
* Recursive substitution in default values: `"${XDG_CONFIG_HOME:$HOME/.config}/my-app/config.toml"`
* Perform substitution on all string values in TOML or YAML data (optional, requires the `toml` or `yaml` feature).
* Perform substitution on all string values in TOML, JSON or YAML data (optional, requires the `toml`, `json` or `yaml` feature).

Variable names can consist of alphanumeric characters and underscores.
They are allowed to start with numbers.
Expand All @@ -27,7 +28,7 @@ There are four different template types to choose from:

## Examples

The [`substitute()`][substitute] function can be used to perform substitution on a `&str`.
The [`substitute()`] function can be used to perform substitution on a `&str`.
The variables can either be a [`HashMap`][std::collections::HashMap] or a [`BTreeMap`][std::collections::BTreeMap].

```rust
Expand All @@ -45,7 +46,7 @@ assert_eq!(
);
```

Substitution can also be done on byte strings using the [`substitute_bytes()`][substitute_bytes] function.
Substitution can also be done on byte strings using the [`substitute_bytes()`] function.

```rust
let mut variables = HashMap::new();
Expand All @@ -56,10 +57,9 @@ assert_eq!(subst::substitute_bytes(b"Hello $name!", &variables)?, b"Hello world!
You can also parse a template once and expand it multiple times:

```rust
let mut variables = HashMap::new();
let template = subst::Template::from_str("Welcome to our hair salon, $name!")?;
for name in ["Scrappy", "Coco"] {
variables.insert("name", name);
let variables: HashMap<_, _> = [("name", name)].into_iter().collect();
let message = template.expand(&variables)?;
println!("{}", message);
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
//!
//! * Perform substitution in `&str` or in `&[u8]`.
//! * Provide a custom map of variables or use environment variables.
//! * Support for `indexmap` (requires the `indexmap` feature).
//! * Short format: `"Hello $name!"`
//! * Long format: `"Hello ${name}!"`
//! * Default values: `"Hello ${name:person}!"`
//! * Recursive substitution in default values: `"${XDG_CONFIG_HOME:$HOME/.config}/my-app/config.toml"`
//! * Perform substitution on all string values in TOML or YAML data (optional, requires the `toml` or `yaml` feature).
//! * Perform substitution on all string values in TOML, JSON or YAML data (optional, requires the `toml`, `json` or `yaml` feature).
//!
//! Variable names can consist of alphanumeric characters and underscores.
//! They are allowed to start with numbers.
Expand All @@ -25,7 +26,7 @@
//!
//! # Examples
//!
//! The [`substitute()`][substitute] function can be used to perform substitution on a `&str`.
//! The [`substitute()`] function can be used to perform substitution on a `&str`.
//! The variables can either be a [`HashMap`][std::collections::HashMap] or a [`BTreeMap`][std::collections::BTreeMap].
//!
//! ```
Expand All @@ -51,7 +52,7 @@
//! # }
//! ```
//!
//! Substitution can also be done on byte strings using the [`substitute_bytes()`][substitute_bytes] function.
//! Substitution can also be done on byte strings using the [`substitute_bytes()`] function.
//!
//! ```
//! # fn main() -> Result<(), subst::Error> {
Expand All @@ -68,10 +69,9 @@
//! ```
//! # fn main() -> Result<(), subst::Error> {
//! # use std::collections::HashMap;
//! let mut variables = HashMap::new();
//! let template = subst::Template::from_str("Welcome to our hair salon, $name!")?;
//! for name in ["Scrappy", "Coco"] {
//! variables.insert("name", name);
//! let variables: HashMap<_, _> = [("name", name)].into_iter().collect();
//! let message = template.expand(&variables)?;
//! println!("{}", message);
//! # assert_eq!(message, format!("Welcome to our hair salon, {name}!"));
Expand Down

0 comments on commit 656f21c

Please sign in to comment.