Struct sgf_parse::SgfNode[][src]

pub struct SgfNode { /* fields omitted */ }

A node in an SGF Game Tree.

By design SgfNode is immutable and can any succesfully constructed SgfNode should be valid and serializable.

If you want to edit an SgfNode convert it into an SgfNodeBuilder using SgfNode::into_builder.

Implementations

impl SgfNode[src]

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

Returns a new SgfNode.

Errors

If the provided children and properties don't correspond to a valid SGF node, then an error is returned.

Examples

use sgf_parse::{serialize, SgfNode, SgfProp, Move, Point};

let children = vec![
    SgfNode::new(
        vec![SgfProp::new("B".to_string(), vec!["dd".to_string()])],
        vec![],
        false,
    ).unwrap()
];

let node = SgfNode::new(vec![SgfProp::SZ((19, 19))], children, true).unwrap();
assert_eq!(serialize(std::iter::once(&node)), "(;SZ[19:19];B[dd])");

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 = &Self> + '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"),
        }
        _ => {},
    }
}

pub fn into_builder(self) -> SgfNodeBuilder[src]

Returns an editable SgfNodeBuilder for the node, consuming it in the process.

Examples

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

let node = parse("(;SZ[13:13];B[de])").unwrap().into_iter().next().unwrap();
let new_prop = SgfProp::new("C".to_string(), vec!["New comment".to_string()]);
let mut builder = node.into_builder();
builder.properties.push(new_prop);
let new_node = builder.build();
let sgf = serialize(&new_node);

assert_eq!(sgf, "(;SZ[13:13]C[New comment];B[de])");

Trait Implementations

impl Clone for SgfNode[src]

impl Debug for SgfNode[src]

impl Display for SgfNode[src]

impl PartialEq<SgfNode> for SgfNode[src]

impl StructuralPartialEq for SgfNode[src]

Auto Trait Implementations

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<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[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.