Crate osmia

Source
Expand description

§osmia

osmia is a clean, expressive templating language rust library designed for building dynamic content in any programming language. Whether you’re generating HTML, SQL, JSON, Java, or configuration files - osmia helps you write templates that are readable, maintainable, and decoupled from your application logic.

§Documentation / Docs:

Official Documentation Repository

§What is osmia?

osmia is a template interpreter — a small, fast engine that reads template files containing dynamic expressions, control flow, and text content, then renders them into plain text output based on the given data.

What sets osmia apart is its language independence. It isn’t tied to any particular language ecosystem. You can embed osmia templates in any project, whether you’re working in Java, Python, C#, Rust, Go, or any other language. This makes it perfect for projects that need flexible template generation without being locked into a specific tech stack.

ProjectDescription
osmia-vscodeExtension for VSCode
osmia-cliCLI tool
docker4osmiaDocker image with osmia-cli

§Use Cases

  • HTML templating in web projects.
  • Formatting JSON from an API response.
  • Code generation for boilerplate in any language.
  • Configuration generation for CI/CD, Kubernetes, etc.
  • Documentation templates with embedded dynamic data.
  • Scripting and scaffolding tools. If you need to render structured files from templates — osmia fits right in.

§Special thanks:

This code was inspired from Crafting Interpreters, by Robert Nystrom.

§Structure:

§Context

The context allows to read and write variables in a Json-like syntax.

Variables, functions and expressions can be stored in the context. The methods for the Expressions are also stored here. See methods in stdlib

The stdlib adds the base for Osmia.

§Examples

use osmia::Osmia;

let mut osmia = Osmia::default();
let output = osmia.run_code("1 + 1 = {{ 1 + 1 }}").unwrap();
assert_eq!(output, "1 + 1 = 2".to_string());

§Json context:

use osmia::Osmia;

let mut osmia = Osmia::try_from(r#"{ "name": "Marvin" }"#).unwrap();
let output = osmia.run_code("Hello {{ name }}!").unwrap();
assert_eq!(output, "Hello Marvin!".to_string());

Modules§

constants 🔒
macros 🔒
model 🔒
stdlib 🔒
types 🔒
utils 🔒

Macros§

impl_debug
Macro that allows to generate easily a custom Debug implementation for an enum.

Structs§

Osmia
Default osmia template engine API.

Traits§

CodeInterpreter