pub fn random_ipv4(args: &HashMap<String, Value>) -> Result<Value>Expand description
A Tera function to generate a random IPv4 address.
The start parameter takes an IPv4 address to indicate the beginning of the
range (inclusive). If start is not passed in, it defaults to 0.0.0.0.
The end parameter also takes an IPv4 address indicating the end of the range,
which is also inclusive. An inclusive range allows 255.255.255.255 to be sampled where an
exclusive range does not. If end is not passed in, it defaults to 255.255.255.255.
It is possible to pass in both start and end, just one of them, or neither.
§Example usage
ⓘ
use tera::{Context, Tera};
use tera_rand::random_ipv4;
let mut tera: Tera = Tera::default();
tera.register_function("random_ipv4", random_ipv4);
let context: Context = Context::new();
// bound by both start and end
let rendered: String = tera
.render_str(r#"{{ random_ipv4(start="127.0.0.0", end="128.0.0.0") }}"#, &context)
.unwrap();
// bound by just start
let rendered: String = tera
.render_str(r#"{{ random_ipv4(start="127.0.0.0") }}"#, &context)
.unwrap();
// bound by just end
let rendered: String = tera
.render_str(r#"{{ random_ipv4(end="128.0.0.0") }}"#, &context)
.unwrap();
// bound by neither start nor end
let rendered: String = tera
.render_str(r#"{{ random_ipv4() }}"#, &context)
.unwrap();