Skip to main content

with_node

Function with_node 

Source
pub fn with_node<T, F, R>(node: &NodePtr, f: F) -> Option<R>
where T: 'static, F: FnOnce(&T) -> R,
Expand description

Get a reference to a node if it is of the specified type and call the closure with the reference. Usage:

use keepass_ng::db::{with_node, Entry, Group, NodePtr, rc_refcell_node};

let node: NodePtr = rc_refcell_node(Group::new("group"));
with_node::<Group, _, _>(&node, |group| {
    // do something with group
});

with_node::<Entry, _, _>(&node, |entry| {
    // do something with entry
});