pub struct SimpleFunction<F>{ /* private fields */ }
Expand description
A wrapper for a Fn(&[String]) -> String
, to be used in Evaluator.
Example:
use rubble_templates_core::evaluator::{Evaluator, Function, SyntaxError};
use std::collections::HashMap;
use rubble_templates_core::functions::SimpleFunction;
fn plus_function(parameters: &[String]) -> String {
parameters.iter()
.map(|param|
param.parse::<i32>().unwrap()
)
.sum::<i32>()
.to_string()
}
let mut functions: HashMap<String, Box<dyn Function>> = HashMap::new();
functions.insert("plus".to_string(), SimpleFunction::new(plus_function)); // will be treated as Box<dyn Function>
Implementations§
Source§impl<F> SimpleFunction<F>
impl<F> SimpleFunction<F>
pub fn new(function: F) -> Box<SimpleFunction<F>>
Trait Implementations§
Auto Trait Implementations§
impl<F> Freeze for SimpleFunction<F>where
F: Freeze,
impl<F> RefUnwindSafe for SimpleFunction<F>where
F: RefUnwindSafe,
impl<F> Send for SimpleFunction<F>where
F: Send,
impl<F> Sync for SimpleFunction<F>where
F: Sync,
impl<F> Unpin for SimpleFunction<F>where
F: Unpin,
impl<F> UnwindSafe for SimpleFunction<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more