pub struct Templates(/* private fields */);Expand description
Structure holding string templates to replace in rules. Templating mechanism allow to define once complex regex and use them at multiple places in rules, making rule maintenance easier.
§Example
use gene::Compiler;
let mut c = Compiler::new();
/// loading template from string
c.load_templates_from_str(
r#"
some_template: hello world
"#,
)
.unwrap();
c.load_rules_from_str(
r#"
name: test
matches:
$m: .data.path == '{{some_template}}'
"#,
).unwrap();
/// we verify our template has been replaced
assert_eq!(
c.rules()
.unwrap()
.first()
.unwrap()
.matches
.as_ref()
.unwrap()
.get("$m")
.unwrap(),
&String::from(".data.path == 'hello world'")
);Implementations§
Source§impl Templates
impl Templates
pub fn new() -> Self
Sourcepub fn insert(&mut self, name: String, template: String) -> Result<(), Error>
pub fn insert(&mut self, name: String, template: String) -> Result<(), Error>
Inserts a new string template. Under the matches section of a Rule
any occurrence of {{name}} (name being the template name) will be
replaced by the template.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Templates
impl<'de> Deserialize<'de> for Templates
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Templates
impl RefUnwindSafe for Templates
impl Send for Templates
impl Sync for Templates
impl Unpin for Templates
impl UnwindSafe for Templates
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