diff --git a/CHANGELOG b/CHANGELOG index 85ddf61..47c8b4d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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. diff --git a/README.md b/README.md index 24a29b0..2402821 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 @@ -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(); @@ -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); } diff --git a/src/lib.rs b/src/lib.rs index 26e7c77..18b106d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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. @@ -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]. //! //! ``` @@ -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> { @@ -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}!"));