Coder Social home page Coder Social logo

frogtd / microtemplate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from legend-of-iphoenix/microtemplate

0.0 0.0 0.0 14 KB

Fast, microscopic helper crate for runtime string interpolation

Home Page: https://crates.io/crates/microtemplate/

Rust 100.00%

microtemplate's Introduction

microtemplate

A fast, microscopic helper crate for runtime string interpolation.

Design Goals

  • Very lightweight: I want microtemplate to do exactly one thing. There's no reason to include more feature-rich/large libraries like regex/handlebars/tinytemplate if all you need is string interpolation.
    • Zero extra runtime sub-dependencies: The only dependencies used are for the derive macro, which is handled at compile time.
  • Fast: I'm interested in making this library as fast as I can make it. It's extremely fast right now, but I do not believe it is perfect.
  • Simple.

Quickstart

Add microtemplate to your dependencies:

[dependencies]
microtemplate = "1.0.2"

Usage example (from the tests):

use microtemplate::{Substitutions, render};

// This derive allows microtemplate to use the struct as substitutions.
#[derive(Substitutions)]
struct Movie<'a> {
    name: &'a str, // automatically replaces "{name}" in a template
    description: &'a str,
}

fn main() {
    let the_birds = Movie {
        name: "The Birds",
        description: "a swarm of birds that suddenly and violently attack the residents of a California coastal town",
    };

    // the template string here can be generated whenever- in this example it
    // is known at compile time but that does not matter.
    let rendered = render("{name} is a movie about {description}.", the_birds);

    // The Birds is a movie about a swarm of birds that suddenly and violently
    // attack the residents of a California coastal town.
    println!("{}", rendered);

    // note that if a substitution is indicated in the template string but it is
    // not found in the struct passed, it is replaced with an empty string ("")
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

If you have any bug reports, improvements, or feature requests, please make an issue

microtemplate's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.