chore(apb): renamed .get and .extract

are now .inner() and .into_inner()
This commit is contained in:
əlemi 2024-11-20 18:03:31 +01:00
parent fc43183ce1
commit 7a78b07467
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -43,6 +43,7 @@ impl<T : super::Base> From<Option<T>> for Node<T> {
impl<T : super::Base> Node<T> {
/// return reference to embedded object (or first if many are present)
#[deprecated = "use .inner() instead"]
pub fn get(&self) -> Option<&T> {
match self {
Node::Empty | Node::Link(_) => None,
@ -51,7 +52,8 @@ impl<T : super::Base> Node<T> {
}
}
/// return reference to embedded object (or first if many are present)
/// return embedded object (or first if many are present)
#[deprecated = "use .into_inner() instead"]
pub fn extract(self) -> Option<T> {
match self {
Node::Empty | Node::Link(_) => None,
@ -60,6 +62,26 @@ impl<T : super::Base> Node<T> {
}
}
/// return reference to embedded object (or first if many are present)
pub fn inner(&self) -> crate::Field<&T> {
match self {
Node::Empty => Err(crate::FieldErr("node is empty")),
Node::Link(_) => Err(crate::FieldErr("node has not been dereferenced")),
Node::Object(x) => Ok(x),
Node::Array(v) => v.iter().next().ok_or(crate::FieldErr("node contains no items"))?.inner(),
}
}
/// return embedded object (or first if many are present)
pub fn into_inner(self) -> crate::Field<T> {
match self {
Node::Empty => Err(crate::FieldErr("node is empty")),
Node::Link(_) => Err(crate::FieldErr("node has not been dereferenced")),
Node::Object(x) => Ok(*x),
Node::Array(v) => v.into_iter().next().ok_or(crate::FieldErr("node contains no items"))?.into_inner(),
}
}
/// true only if Node is empty
pub fn is_empty(&self) -> bool {
matches!(self, Node::Empty)