[][src]Enum sise::Node

pub enum Node {
    Atom(String),
    List(Vec<Node>),
}

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

Methods

impl Node[src]

pub fn ref_as_usize(&self) -> usize[src]

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);

pub fn is_atom(&self) -> bool[src]

Return whether the node is an Atom.

pub fn is_list(&self) -> bool[src]

Return whether the node is a List.

pub fn into_atom(self) -> Option<String>[src]

Consumes the node and returns the atom value if it is an Atom.

pub fn into_list(self) -> Option<Vec<Node>>[src]

Consumes the node and returns the list if it is a List.

pub fn as_atom(&self) -> Option<&String>[src]

Returns a reference to the atom value if the node is an Atom.

pub fn as_list(&self) -> Option<&Vec<Node>>[src]

Returns a reference to the list if the node is a List.

pub fn as_mut_atom(&mut self) -> Option<&mut String>[src]

Returns a mutable reference to the atom value if the node is an Atom.

pub fn as_mut_list(&mut self) -> Option<&mut Vec<Node>>[src]

Returns mutable a reference to the list if the node is a List.

pub fn index_path(&self, path: &[usize]) -> Option<&Self>[src]

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());

Trait Implementations

impl PartialEq<Node> for Node[src]

impl PartialEq<str> for Node[src]

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl<'_> PartialEq<&'_ str> for Node[src]

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl PartialEq<String> for Node[src]

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl Eq for Node[src]

impl<'a> From<&'a str> for Node[src]

impl From<String> for Node[src]

impl From<Vec<Node>> for Node[src]

impl Clone for Node[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Hash for Node[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Debug for Node[src]

Auto Trait Implementations

impl Send for Node

impl Unpin for Node

impl Sync for Node

impl UnwindSafe for Node

impl RefUnwindSafe for Node

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]