Struct sgf_parse::SgfNodeBuilder[][src]

pub struct SgfNodeBuilder {
    pub properties: Vec<SgfProp>,
    pub children: Vec<SgfNodeBuilder>,
    pub is_root: bool,
}

A builder for SgfNodes.

SgfNodes are immutable and required to be valid from the time of creation. An SgfNodeBuilder can be used to construct a complicated game tree which can then be converted to an SgfNode with little overhead. If you're building an SGF file from scratch, this should be your starting point. If you want to modify an existing SGF, SgfNode::into_builder will get you an SgfNodeBuilder to work with.

Note that SgfNodeBuilder performs no validation until you call the build method. The user is responsible for ensuring that no invalid combination of properties has been set.

Examples

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

let mut node = SgfNodeBuilder::new();
node.properties.push(SgfProp::new("B".to_string(), vec!["jj".to_string()]));
let mut child = SgfNodeBuilder::new();
child.properties.push(SgfProp::new("W".to_string(), vec!["cd".to_string()]));
node.children.push(child);

let node = node.build();
let sgf = serialize(&node);

assert_eq!(sgf, "(;B[jj];W[cd])");

Fields

properties: Vec<SgfProp>children: Vec<SgfNodeBuilder>is_root: bool

Implementations

impl SgfNodeBuilder[src]

pub fn new() -> Self[src]

Return a new empty SgfNodeBuilder.

pub fn build(self) -> Result<SgfNode, SgfParseError>[src]

Consume the SgfNodeBuilder and its children and return an SgfNode.

Errors

If the SgfNode or any of its children are invalid, then an error is returned.

Trait Implementations

impl Clone for SgfNodeBuilder[src]

impl Debug for SgfNodeBuilder[src]

impl Default for SgfNodeBuilder[src]

impl PartialEq<SgfNodeBuilder> for SgfNodeBuilder[src]

impl StructuralPartialEq for SgfNodeBuilder[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, 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.