use super::*;
impl<N: Network> Record<N, Plaintext<N>> {
pub fn find<A: Into<Access<N>> + Copy + Debug>(&self, path: &[A]) -> Result<Entry<N, Plaintext<N>>> {
if path.len() == 1 && path[0].into() == Access::Member(Identifier::from_str("owner")?) {
return Ok(self.owner.to_entry());
}
if let Some((first, rest)) = path.split_first() {
let first = match (*first).into() {
Access::Member(identifier) => identifier,
Access::Index(_) => bail!("Attempted to index into a record"),
};
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.")
}
}
}