Rust లో Go html/template తరహా rendering.

go_html_template అనేది Go html/template యొక్క ప్రధాన workflows ను అనుకరించే Rust crate. ఇది template syntax, pipelines, context-aware escaping, మరియు unsafe URL scheme blocking ను support చేస్తూ పరిచితమైన API shape ను ఉంచుతుంది.

Go తరహా Template API

Template::new(...).parse(...).execute(...) ను define / template / range / with / pipeline features తో ఉపయోగించండి.

సందర్భ-ఆధారిత escaping

HTML text, attributes, URL attributes, మరియు script / style contexts కోసం context-aware escaping ను అమలు చేసి unsafe javascript: URLs ను block చేస్తుంది.

web-rust మోడ్

web-rust feature తో parse_files / parse_glob / parse_fs disable అవుతాయి; అందువల్ల in-memory template loading ను enforce చేయవచ్చు.

సెటప్ మరియు ప్రాథమిక వినియోగం

Crate ను జోడించి, కనీస parse + execute_to_string flow ను verify చేయండి. web-rust environments లో file-loading APIs బదులుగా in-memory template strings ను ఉపయోగించండి.

ఇన్‌స్టాల్

cargo add go_html_template

Rust ఉదాహరణ

src/main.rs
use go_html_template::{Template, Value};

fn main() -> Result<(), Box<dyn std::error::Error>> {
  let tpl = Template::new("page")
    .parse(r#"<h1>{{.Title}}</h1>\n<p>{{.Body | safe_html}}</p>"#)?;

  let out = tpl.execute_to_string(&serde_json::json!({
    "Title": "go_html_template",
    "Body": "<em>trusted</em>"
  }))?;

  println!("{out}");
  Ok(())
}
అనుకూలత స్థితి

ప్రస్తుతం go_html_template core workflows ను అమలు చేస్తూ compatibility gaps ను క్రమంగా తగ్గిస్తోంది . ఇది ఇంకా Go html/template కు strict 1:1 compatibility లక్ష్యం కాదు; కాబట్టి production templates లో behavior ను తప్పక verify చేయండి.