pobsd_db/
lib.rs

1//! This library provides a set of methods to interrogate the PlayOnBSD
2//! database in a friendly manner, without having to deal with a SQL
3//! database.
4//! ## Examples
5//! Create a GameDataBase from the PlayOnBSD database.
6//! ```no_run
7//! extern crate pobsd_db;
8//! extern crate pobsd_parser;
9//! use pobsd_db::GameDataBase;
10//! use pobsd_parser::{Game, Parser, ParserResult, ParsingMode};
11//! // loading the games from the database
12//! let games = match Parser::new(ParsingMode::Strict)
13//!        .load_from_file("games.db")
14//!        .expect("Could not open the file")
15//!    {
16//!        ParserResult::WithoutError(games) => games,
17//!        ParserResult::WithError(games, _) => games,
18//!    };
19//! GameDataBase::new(games);
20//!```
21//! Get a game by name.
22//! ```no_run
23//! # extern crate pobsd_db;
24//! # extern crate pobsd_parser;
25//! # use pobsd_db::GameDataBase;
26//! # use pobsd_parser::{Game, Parser, ParserResult, ParsingMode};
27//! # let games = match Parser::new(ParsingMode::Strict)
28//! #       .load_from_file("games.db")
29//! #       .expect("Could not open the file")
30//! #   {
31//! #       ParserResult::WithoutError(games) => games,
32//! #       ParserResult::WithError(games, _) => games,
33//! #   };
34//! # let db = GameDataBase::new(games);
35//! if let Some(game) = db.get_game_by_name("My Game"){
36//!     assert_eq!(&game.name, "My Game");
37//! };
38//!```
39//! Get all games associated to a given tag.
40//! ```no_run
41//! # extern crate pobsd_db;
42//! # extern crate pobsd_parser;
43//! # use pobsd_db::GameDataBase;
44//! # use pobsd_parser::{Game, Parser, ParserResult, ParsingMode};
45//! # let games = match Parser::new(ParsingMode::Strict)
46//! #       .load_from_file("games.db")
47//! #       .expect("Could not open the file")
48//! #   {
49//! #       ParserResult::WithoutError(games) => games,
50//! #       ParserResult::WithError(games, _) => games,
51//! #   };
52//! # let db = GameDataBase::new(games);
53//! let game_query = db.get_game_by_tag("indie");
54//! // check the first element of the query
55//! if let Some(game) = game_query.get(0) {
56//!     if let Some(tags) = &game.tags {
57//!         assert!(tags.join(" ").contains("indie"));
58//!     };
59//! };
60//!```
61pub mod database;
62pub(crate) mod queries;
63pub mod query_result;
64
65pub use database::GameDataBase;
66pub use query_result::QueryResult;
67
68/// Representation of items such as pub, tags, etc.
69pub type Item = String;