Expand description
A SISE 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<Node>)
A list of nodes
Implementations§
source§impl Node
impl Node
sourcepub fn ref_as_usize(&self) -> usize
pub fn ref_as_usize(&self) -> usize
Bitcasts the reference to self
to usize
. Useful
to insert it in a HashSet<usize>
, which is used
by sise::SpacedSerializeStyle
.
Example
let node = sise::Node::Atom(String::from("example"));
assert_eq!(node.ref_as_usize(), &node as *const sise::Node as usize);
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<Node>>
pub fn into_list(self) -> Option<Vec<Node>>
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<Node>>
pub fn as_list(&self) -> Option<&Vec<Node>>
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<Node>>
pub fn as_mut_list(&mut self) -> Option<&mut Vec<Node>>
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_expr;
let tree = sise_expr!(["example", ["1", "2", "3"], ["a", "b", "c"]]);
assert_eq!(*tree.index_path(&[0]).unwrap(), "example");
assert_eq!(*tree.index_path(&[1]).unwrap(), sise_expr!(["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());