| Crates.io | good-morning |
| lib.rs | good-morning |
| version | 0.1.2 |
| created_at | 2025-12-26 15:54:45.827733+00 |
| updated_at | 2025-12-26 17:57:12.577071+00 |
| description | A welcome message generator. |
| homepage | |
| repository | https://github.com/xiao-e-yun/good-morning |
| max_upload_size | |
| id | 2005895 |
| size | 28,918 |
A tiny Rust crate that generates welcome messages.
Add this crate to your Cargo.toml:
[dependencies]
good-morning = "0.1"
Basic usage: create GoodMorning, load a template, provide arguments, and execute.
use good_morning::GoodMorning;
use std::collections::HashMap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut gm = GoodMorning::new();
// Load a single template (supports variables)
gm.load_template("Hello, {name}!")?;
let args = HashMap::from([
("name".to_string(), "World".to_string()),
]);
let msg = gm.execute(&args)?;
println!("{}", msg); // Hello, World!
Ok(())
}
Add a modifier after the variable name (e.g., uppercase / lowercase).
use good_morning::GoodMorning;
use std::collections::HashMap;
let mut gm = GoodMorning::new();
gm.load_template("Hello, {name:uppercase}!")?;
let args = HashMap::from([
("name".to_string(), "alice".to_string()),
]);
let msg = gm.execute(&args)?;
assert_eq!(msg, "Hello, ALICE!");
Load multiple templates at once (lines starting with # are comments).
use good_morning::GoodMorning;
let mut gm = GoodMorning::new();
gm.load_templates_from_file("assets/templates.txt")?;
When multiple templates exist, use execute_with_required to require specific flags (flags are derived from variable names).
use good_morning::GoodMorning;
use std::collections::HashMap;
let mut gm = GoodMorning::new();
gm.load_template("Hello, {name}!")?;
let args = HashMap::from([
("name".to_string(), "Bob".to_string()),
]);
let msg = gm.execute_with_required(&args, vec!["name".to_string()])?;
Full API docs on docs.rs: https://docs.rs/good-morning
More examples in src and the API example in examples/api_server.
MIT