pub fn parse<R: BufRead>(source: R, path: Option<PathBuf>) -> Result<Run> {
    let reader = &mut Reader::from_reader(source);
    reader.expand_empty_elements(true);
    reader.trim_text(true);

    let mut buf = Vec::with_capacity(4096);
    let mut buf2 = Vec::with_capacity(4096);

    let mut run = Run::new();

    let mut required_flags = 0u8;

    parse_base(reader, &mut buf, b"Run", |reader, tag| {
        let mut version = Version(1, 0, 0, 0);
        type_hint(optional_attribute_err(&tag, b"version", |t| {
            version = parse_version(t)?;
            Ok(())
        }))?;

        parse_children(reader, tag.into_buf(), |reader, tag| {
            if tag.name() == b"GameIcon" {
                required_flags |= 1;
                image(reader, tag.into_buf(), &mut buf2, |i| run.set_game_icon(i))
            } else if tag.name() == b"GameName" {
                required_flags |= 1 << 1;
                text(reader, tag.into_buf(), |t| run.set_game_name(t))
            } else if tag.name() == b"CategoryName" {
                required_flags |= 1 << 2;
                text(reader, tag.into_buf(), |t| run.set_category_name(t))
            } else if tag.name() == b"Offset" {
                required_flags |= 1 << 3;
                time_span(reader, tag.into_buf(), |t| run.set_offset(t))
            } else if tag.name() == b"AttemptCount" {
                required_flags |= 1 << 4;
                text_parsed(reader, tag.into_buf(), |t| run.set_attempt_count(t))
            } else if tag.name() == b"AttemptHistory" {
                parse_attempt_history(version, reader, tag.into_buf(), &mut run)
            } else if tag.name() == b"RunHistory" {
                parse_run_history(version, reader, tag.into_buf(), &mut run)
            } else if tag.name() == b"Metadata" {
                parse_metadata(version, reader, tag.into_buf(), run.metadata_mut())
            } else if tag.name() == b"Segments" {
                required_flags |= 1 << 5;
                parse_children(reader, tag.into_buf(), |reader, tag| {
                    if tag.name() == b"Segment" {
                        let segment =
                            parse_segment(version, reader, tag.into_buf(), &mut buf2, &mut run)?;
                        run.push_segment(segment);
                        Ok(())
                    } else {
                        end_tag(reader, tag.into_buf())
                    }
                })
            } else if tag.name() == b"AutoSplitterSettings" {
                let settings = run.auto_splitter_settings_mut();
                reencode_children(reader, tag.into_buf(), settings).map_err(Into::into)
            } else {
                end_tag(reader, tag.into_buf())
            }
        })
    })?;

    if required_flags != (1 << 6) - 1 {
        return Err(Error::Xml {
            source: XmlError::ElementNotFound,
        });
    }

    run.set_path(path);

    Ok(run)
}
/// Attempts to parse a LiveSplit splits file. In addition to the source to
/// parse, you can provide a path to the splits file, which helps saving the
/// splits file again later.
Attempts to parse a LiveSplit splits file. In addition to the source to
parse, you can provide a path to the splits file, which helps saving the
splits file again later.
Attempts to parse a LiveSplit splits file . In addition to the source to parse you can provide a path to the splits file which helps saving the splits file again later .
pub fn parse<R: BufRead>(source: R, path: Option<PathBuf>) -> Result<Run> {
    let reader = &mut Reader::from_reader(source);
    reader.expand_empty_elements(true);
    reader.trim_text(true);
    let mut buf = Vec::with_capacity(4096);
    let mut buf2 = Vec::with_capacity(4096);
    let mut run = Run::new();
    let mut required_flags = 0u8;
    parse_base(reader, &mut buf, b"Run", |reader, tag| {
        let mut version = Version(1, 0, 0, 0);
        type_hint(optional_attribute_err(&tag, b"version", |t| {
            version = parse_version(t)?;
            Ok(())
        }))?;
        parse_children(reader, tag.into_buf(), |reader, tag| {
            if tag.name() == b"GameIcon" {
                required_flags |= 1;
                image(reader, tag.into_buf(), &mut buf2, |i| run.set_game_icon(i))
            } else if tag.name() == b"GameName" {
                required_flags |= 1 << 1;
                text(reader, tag.into_buf(), |t| run.set_game_name(t))
            } else if tag.name() == b"CategoryName" {
                required_flags |= 1 << 2;
                text(reader, tag.into_buf(), |t| run.set_category_name(t))
            } else if tag.name() == b"Offset" {
                required_flags |= 1 << 3;
                time_span(reader, tag.into_buf(), |t| run.set_offset(t))
            } else if tag.name() == b"AttemptCount" {
                required_flags |= 1 << 4;
                text_parsed(reader, tag.into_buf(), |t| run.set_attempt_count(t))
            } else if tag.name() == b"AttemptHistory" {
                parse_attempt_history(version, reader, tag.into_buf(), &mut run)
            } else if tag.name() == b"RunHistory" {
                parse_run_history(version, reader, tag.into_buf(), &mut run)
            } else if tag.name() == b"Metadata" {
                parse_metadata(version, reader, tag.into_buf(), run.metadata_mut())
            } else if tag.name() == b"Segments" {
                required_flags |= 1 << 5;
                parse_children(reader, tag.into_buf(), |reader, tag| {
                    if tag.name() == b"Segment" {
                        let segment =
                            parse_segment(version, reader, tag.into_buf(), &mut buf2, &mut run)?;
                        run.push_segment(segment);
                        Ok(())
                    } else {
                        end_tag(reader, tag.into_buf())
                    }
                })
            } else if tag.name() == b"AutoSplitterSettings" {
                let settings = run.auto_splitter_settings_mut();
                reencode_children(reader, tag.into_buf(), settings).map_err(Into::into)
            } else {
                end_tag(reader, tag.into_buf())
            }
        })
    })?;
    if required_flags != (1 << 6) - 1 {
        return Err(Error::Xml {
            source: XmlError::ElementNotFound,
        });
    }
    run.set_path(path);
    Ok(run)
}
pub fn parse < R : BufRead > ( source : R , path : Option < PathBuf > ) -> Result < Run > { let reader = & mut Reader :: from_reader ( source ) ; reader . expand_empty_elements ( true ) ; reader . trim_text ( true ) ; let mut buf = Vec :: with_capacity ( 4096 ) ; let mut buf2 = Vec :: with_capacity ( 4096 ) ; let mut run = Run :: new ( ) ; let mut required_flags = 0u8 ; parse_base ( reader , & mut buf , b" " , | reader , tag | { let mut version = Version ( 1 , 0 , 0 , 0 ) ; type_hint ( optional_attribute_err ( & tag , b" " , | t | { version = parse_version ( t ) ? ; Ok ( ( ) ) } ) ) ? ; parse_children ( reader , tag . into_buf ( ) , | reader , tag | { if tag . name ( ) == b" " { required_flags |= 1 ; image ( reader , tag . into_buf ( ) , & mut buf2 , | i | run . set_game_icon ( i ) ) } else if tag . name ( ) == b" " { required_flags |= 1 << 1 ; text ( reader , tag . into_buf ( ) , | t | run . set_game_name ( t ) ) } else if tag . name ( ) == b" " { required_flags |= 1 << 2 ; text ( reader , tag . into_buf ( ) , | t | run . set_category_name ( t ) ) } else if tag . name ( ) == b" " { required_flags |= 1 << 3 ; time_span ( reader , tag . into_buf ( ) , | t | run . set_offset ( t ) ) } else if tag . name ( ) == b" " { required_flags |= 1 << 4 ; text_parsed ( reader , tag . into_buf ( ) , | t | run . set_attempt_count ( t ) ) } else if tag . name ( ) == b" " { parse_attempt_history ( version , reader , tag . into_buf ( ) , & mut run ) } else if tag . name ( ) == b" " { parse_run_history ( version , reader , tag . into_buf ( ) , & mut run ) } else if tag . name ( ) == b" " { parse_metadata ( version , reader , tag . into_buf ( ) , run . metadata_mut ( ) ) } else if tag . name ( ) == b" " { required_flags |= 1 << 5 ; parse_children ( reader , tag . into_buf ( ) , | reader , tag | { if tag . name ( ) == b" " { let segment = parse_segment ( version , reader , tag . into_buf ( ) , & mut buf2 , & mut run ) ? ; run . push_segment ( segment ) ; Ok ( ( ) ) } else { end_tag ( reader , tag . into_buf ( ) ) } } ) } else if tag . name ( ) == b" " { let settings = run . auto_splitter_settings_mut ( ) ; reencode_children ( reader , tag . into_buf ( ) , settings ) . map_err ( Into :: into ) } else { end_tag ( reader , tag . into_buf ( ) ) } } ) } ) ? ; if required_flags != ( 1 << 6 ) - 1 { return Err ( Error :: Xml { source : XmlError :: ElementNotFound , } ) ; } run . set_path ( path ) ; Ok ( run ) }
Attempts to parse a LiveSplit splits file.
Attempts to parse a LiveSplit splits file .
source
R
path
Option<PathBuf>
source
R
path
Option<PathBuf>