Skip to main content

Crate gtmpl_value_ng

Crate gtmpl_value_ng 

Source
Expand description

gtmpl_value_ng holds the value type used by gtmpl-ng, the Golang templating language for Rust. A Value is what a template parses its literals into and what a context hands it back.

The From trait is implemented for:

  • String, &str, Cow<str>
  • most numeric types u64, u32, …, i64, i32, …, f64, f32
  • bool
  • Vec<Value>, &[Value]
  • HashMap<String, Value>
  • Option<T>, where None becomes Value::NoValue

gtmpl_derive_ng derives it for a struct.

§Examples

use gtmpl_value_ng::Value;

let v: Value = "something".into();
assert_eq!(v.to_string(), "something");

§Relation to gtmpl_value

This crate is a fork of gtmpl_value by Florian Dieminger, taken from its master branch at a333139 — which is two years ahead of the last release on crates.io and carries the fix for negative non-integer numbers that 0.5.1 truncates. It lives in the same workspace as the engine so that the value type and the engine are released together.

With the gtmpl_value_compat feature, Value gains a TryFrom conversion from gtmpl_value::Value, so a tree that still derives against the published crate can be migrated one call site at a time.

Structs§

Function
Wrapper struct for Func.
Number
Internal number format for gtmpl_value_ng.

Enums§

FloatFormat
Which of Go’s float formats to use.
FromLegacyValueError
Why a gtmpl_value::Value could not be converted.
FuncError
NumberKind
Which of the three representations a Number holds.
Value
Represents a gtmpl value.

Traits§

FromValue
Convert Value into something.

Functions§

format_float
Formats a float the way Go’s strconv.FormatFloat does.
from_value
FromValue wrapped in a macro (required for gtmpl_fn! macro).
write_float
Writes a float the way Go’s strconv.FormatFloat does.

Type Aliases§

Func
Function type supported by gtmpl_value_ng.