Struct sgf_parse::SgfNode [−][src]
pub struct SgfNode<Prop: SgfProp> { pub properties: Vec<Prop>, pub children: Vec<Self>, pub is_root: bool, }
Expand description
A node in an SGF Game Tree.
Any succesfully constructed node will be serializable, but may or may not be valid.
All game-specific information is encoded in the Prop
type. Use
go::Prop
for go games, and
unknown_game::Prop
for all other games.
Fields
properties: Vec<Prop>
children: Vec<Self>
is_root: bool
Implementations
Returns a new node.
Examples
use sgf_parse::{SgfNode, SgfProp}; use sgf_parse::go::Prop; let children = vec![ SgfNode::<Prop>::new( vec![Prop::new("B".to_string(), vec!["dd".to_string()])], vec![], false, ), ]; let node = SgfNode::new(vec![Prop::SZ((19, 19))], children, true);
Returns the property with the provided identifier for the node (if present).
Examples
use sgf_parse::go::{parse, Prop}; let node = parse("(;SZ[13:13];B[de])").unwrap().into_iter().next().unwrap(); let board_size = match node.get_property("SZ") { Some(Prop::SZ(size)) => size.clone(), None => (19, 19), _ => unreachable!(), };
Returns an iterator over the children of this node.
Examples
use sgf_parse::go::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!") } }
Returns an iterator over the properties of this node.
Examples
use sgf_parse::go::{parse, Move, Prop}; let node = parse("(;B[de]C[A comment])").unwrap().into_iter().next().unwrap(); for prop in node.properties() { match prop { Prop::B(mv) => match mv { Move::Move(p) => println!("B Move at {}, {}", p.x, p.y), Move::Pass => println!("B Pass"), } Prop::W(mv) => match mv { Move::Move(p) => println!("W Move at {}, {}", p.x, p.y), Move::Pass => println!("W Pass"), } _ => {}, } }
Returns the serialized SGF for this SgfNode as a complete GameTree.
Examples
use sgf_parse::go::parse; let sgf = "(;SZ[13:13];B[de])"; let node = parse(sgf).unwrap().into_iter().next().unwrap(); assert_eq!(node.serialize(), sgf);
Returns Ok
if the node’s properties are valid according to the SGF FF[4] spec.
Errors
Returns an error if the node has invalid properties.
Examples
use sgf_parse::InvalidNodeError; use sgf_parse::go::parse; let node = parse("(;B[de]C[A comment]C[Another])").unwrap().into_iter().next().unwrap(); let result = node.validate(); assert!(matches!(result, Err(InvalidNodeError::RepeatedIdentifier(_))));
Trait Implementations
Auto Trait Implementations
impl<Prop> RefUnwindSafe for SgfNode<Prop> where
Prop: RefUnwindSafe,
impl<Prop> UnwindSafe for SgfNode<Prop> where
Prop: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more