chore(apb): renamed .get and .extract
are now .inner() and .into_inner()
This commit is contained in:
parent
fc43183ce1
commit
7a78b07467
1 changed files with 23 additions and 1 deletions
|
@ -43,6 +43,7 @@ impl<T : super::Base> From<Option<T>> for Node<T> {
|
||||||
|
|
||||||
impl<T : super::Base> Node<T> {
|
impl<T : super::Base> Node<T> {
|
||||||
/// return reference to embedded object (or first if many are present)
|
/// return reference to embedded object (or first if many are present)
|
||||||
|
#[deprecated = "use .inner() instead"]
|
||||||
pub fn get(&self) -> Option<&T> {
|
pub fn get(&self) -> Option<&T> {
|
||||||
match self {
|
match self {
|
||||||
Node::Empty | Node::Link(_) => None,
|
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> {
|
pub fn extract(self) -> Option<T> {
|
||||||
match self {
|
match self {
|
||||||
Node::Empty | Node::Link(_) => None,
|
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
|
/// true only if Node is empty
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
matches!(self, Node::Empty)
|
matches!(self, Node::Empty)
|
||||||
|
|
Loading…
Reference in a new issue