[][src]Struct sgf_parse::SgfNode

pub struct SgfNode { /* fields omitted */ }

A node in an SGF Game Tree.

Implementations

impl SgfNode[src]

pub fn new(
    props: Vec<SgfProp>,
    children: Vec<SgfNode>,
    is_root: bool
) -> Result<SgfNode, SgfParseError>
[src]

pub fn get_property(&self, identifier: &str) -> Option<&SgfProp>[src]

Returns the property with the provided identifier for the node (if present).

Examples

use sgf_parse::{parse, SgfProp};

let node = parse("(;SZ[13:13];B[de])").unwrap().into_iter().next().unwrap();
let board_size = match node.get_property("SZ") {
    Some(SgfProp::SZ(size)) => size.clone(),
    None => (19, 19),
    _ => unreachable!(),
};

pub fn children<'a>(&'a self) -> impl Iterator<Item = &SgfNode> + 'a[src]

Returns an iterator over the children of this node.

Examples

use sgf_parse::parse;

let node = parse("(;SZ[19](;B[de])(;B[dd]HO[2]))").unwrap().into_iter().next().unwrap();
for child in node.children() {
    if let Some(prop) = child.get_property("HO") {
       println!("Found a hotspot!")
    }
}

pub fn properties<'a>(&'a self) -> impl Iterator<Item = &SgfProp> + 'a[src]

Returns an iterator over the properties of this node.

Examples

use sgf_parse::{parse, SgfProp, Move};

let node = parse("(;B[de]C[A comment])").unwrap().into_iter().next().unwrap();
for prop in node.properties() {
    match prop {
        SgfProp::B(mv) => match mv {
            Move::Move(p) => println!("B Move at {}, {}", p.x, p.y),
            Move::Pass => println!("B Pass"),
        }
        SgfProp::W(mv) => match mv {
            Move::Move(p) => println!("W Move at {}, {}", p.x, p.y),
            Move::Pass => println!("W Pass"),
        }
        _ => {},
    }
}

Trait Implementations

impl Clone for SgfNode[src]

impl Debug for SgfNode[src]

impl IntoIterator for SgfNode[src]

type Item = SgfNode

The type of the elements being iterated over.

type IntoIter = IntoIter<Self::Item>

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl RefUnwindSafe for SgfNode

impl Send for SgfNode

impl Sync for SgfNode

impl Unpin for SgfNode

impl UnwindSafe for SgfNode

Blanket Implementations

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

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

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

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

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

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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

type Owned = T

The resulting type after obtaining ownership.

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.