Expand description
A SISE tree node.
Variants
Atom(String)
An atom, that matches the following regular expression:
"([:atomchar:]|\"(\\([:stringchar:]|\\|\")|[:stringchar:])+\")+"
Where :atomchar:
is one of:
!
,#
,$
,%
,&
,*
,+
,-
,.
,/
,:
,<
,=
,>
,?
,@
,_
,~
And :stringchar:
is any character between ASCII space and ~
,
except \
and "
.
Atoms are not interpreted in any way, the crate sise_atom
provides
functions to encode and decode atoms as strings, numbers, booleans…
List(Vec<TreeNode>)
A list of nodes
Implementations
sourceimpl TreeNode
impl TreeNode
sourcepub fn into_atom(self) -> Option<String>
pub fn into_atom(self) -> Option<String>
Consumes the node and returns the atom value if it is an
Atom
.
sourcepub fn into_list(self) -> Option<Vec<Self>>
pub fn into_list(self) -> Option<Vec<Self>>
Consumes the node and returns the list if it is a
List
.
sourcepub fn as_atom(&self) -> Option<&String>
pub fn as_atom(&self) -> Option<&String>
Returns a reference to the atom value if the node is
an Atom
.
sourcepub fn as_list(&self) -> Option<&Vec<Self>>
pub fn as_list(&self) -> Option<&Vec<Self>>
Returns a reference to the list if the node is
a List
.
sourcepub fn as_mut_atom(&mut self) -> Option<&mut String>
pub fn as_mut_atom(&mut self) -> Option<&mut String>
Returns a mutable reference to the atom value if the node is
an Atom
.
sourcepub fn as_mut_list(&mut self) -> Option<&mut Vec<Self>>
pub fn as_mut_list(&mut self) -> Option<&mut Vec<Self>>
Returns mutable a reference to the list if the node is
a List
.
sourcepub fn index_path(&self, path: &[usize]) -> Option<&Self>
pub fn index_path(&self, path: &[usize]) -> Option<&Self>
Traverses a tree with indices from path
.
Example
use sise::sise_tree;
// (example (1 2 3) (a b c))
let tree = sise_tree!(["example", ["1", "2", "3"], ["a", "b", "c"]]);
assert_eq!(*tree.index_path(&[]).unwrap(), tree);
assert_eq!(*tree.index_path(&[0]).unwrap(), "example");
assert_eq!(*tree.index_path(&[1]).unwrap(), sise_tree!(["1", "2", "3"]));
assert_eq!(tree.index_path(&[1, 0]).unwrap(), "1");
assert_eq!(tree.index_path(&[2, 0]).unwrap(), "a");
assert!(tree.index_path(&[3]).is_none());
assert!(tree.index_path(&[0, 1]).is_none());
Trait Implementations
impl Eq for TreeNode
impl StructuralEq for TreeNode
impl StructuralPartialEq for TreeNode
Auto Trait Implementations
impl RefUnwindSafe for TreeNode
impl Send for TreeNode
impl Sync for TreeNode
impl Unpin for TreeNode
impl UnwindSafe for TreeNode
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more