Expand description
Provides a simplistic Parser
that converts
the PlayOnBSD Database
(either provided as a string or as a file) into a vector of Game
s.
§Examples
Here is a first example loading a file in relaxed mode (by default).
use libpobsd::{Parser, ParserResult};
// Create a parser
let parser = Parser::default();
// Load the database
let parser_result = parser.load_from_file("/path/to/games.db")
.expect("Problem trying to open the file");
let games = match parser_result {
ParserResult::WithoutError(games) => games,
ParserResult::WithError(games, _) => games,
};
The parser can also use a strict mode in which it will stop when encountering a parsing error and returning the games it has processed.
use libpobsd::{Parser, ParserResult, ParsingMode};
// Create a parser in strict mode
let parser = Parser::new(ParsingMode::Strict);
// Load the database
let parser_result = parser.load_from_file("/path/to/games.db")
.expect("Problem trying to open the file");
let games = match parser_result {
ParserResult::WithoutError(games) => games,
ParserResult::WithError(games, _) => games,
};
The parser can also load from a &str
or a String
.
use libpobsd::{Parser, ParserResult, ParsingMode, Game};
let games = r#"Game AaaaaAAaaaAAAaaAAAAaAAAAA!!! for the Awesome
Cover AaaaaA_for_the_Awesome_Cover.jpg
Engine
Setup
Runtime HumblePlay
Store https://www.humblebundle.com/store/aaaaaaaaaaaaaaaaaaaaaaaaa-for-the-awesome
Hints Demo on HumbleBundle store page
Genre
Tags
Year 2011
Dev
Pub
Version
Status
Added 1970-01-01
Updated 1970-01-01
IgdbId 12
Game The Adventures of Mr. Hat
Cover
Engine godot
Setup
Runtime godot
Store https://store.steampowered.com/app/1869200/The_Adventures_of_Mr_Hat/
Hints
Genre Puzzle Platformer
Tags indie
Year
Dev AX-GAME
Pub Fun Quarter
Version Early Access
Status runs (2022-05-13)
Added 2022-05-13
Updated 2022-05-13
IgdbId 13"#;
let parser = Parser::default();
let games = match parser.load_from_string(games) {
ParserResult::WithoutError(games) => games,
// Should not panic since the data are fine
ParserResult::WithError(_, _) => panic!(),
};
let game1: &Game = games.get(1).unwrap();
assert_eq!(Some(String::from("godot")), game1.engine);
Structs§
- Parses the PlayOnBSD database provided as a
&str
or from a file and returns aParserResult
holding a vector ofGame
contained in the PlayOnBSD database.
Enums§
- Represents the result of the parsing. When in strict mode, only the games parsed before a parsing error occurred will be returned. In relaxed mode, the parser will do its best to continue parsing games.
- Represents the two parsing modes supported by
Parser
.