[][src]Crate germinate

This crate provides a method of injecting variables from multiple external sources into a template string. Sources can be anything as long as they implement the Loader trait which handles the loading of the variables in a standard way.

Sources

Built In

These are the currently implemented sources and their associated template keys

SourceKeyDescription
AWS EC2 Instance Tagsawsec2tagLoad the value of AWS EC2 Instance Tags by their key
AWS EC2 Metadata Serviceawsec2metadataLoad a value from the AWS EC2 Metadata Service by it's path
Environment VariablesenvLoad the value of an environment variable

Example

let mut seed = Seed::new("Hi %env:NAME%!");
let output = seed.germinate().await?;

assert_eq!("Hi John!", output);

Custom Sources

You can also include your own sources using the Seed::add_custom_loader method. The only requirement is that the custom loader must implement the Loader trait

Example

let mut seed = Seed::new("Hi %name:name%");

// Add a custom loader for the name key. This is the loader that will be used whenever
// germinate finds %name:...% in the template string
seed.add_custom_loader("name".to_string(), Box::new(NameLoader {}));

let output = seed.germinate().await?;

assert_eq!("Hi John", output);

Structs

Seed

A Seed is responsible for parsing the template string, loading the values, and optionally making the replacements via the germinate method

Traits

Loader

A type implementing the Loader trait can be used to load a value from a store by it's key