use super::*;
impl<N: Network> Record<N, Plaintext<N>> {
pub fn find(&self, path: &[Identifier<N>]) -> Result<Entry<N, Plaintext<N>>> {
if path.len() == 1 {
if path[0] == Identifier::from_str("owner")? {
return Ok(self.owner.to_entry());
} else if path[0] == Identifier::from_str("gates")? {
return Ok(self.gates.to_entry());
}
}
if let Some((first, rest)) = path.split_first() {
match self.data.get(first) {
Some(entry) => match rest.is_empty() {
true => Ok(entry.clone()),
false => entry.find(rest),
},
None => bail!("Record entry `{first}` not found."),
}
} else {
bail!("Attempted to find record entry with an empty path.")
}
}
}