mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 15:27:28 +00:00
* Implement generic response as enum * First draft of implementing into_common() * Make common response type generic * Use macros and generics to reduce repetition * [Games] Add dynamically dispatched CommonResponse trait This adds two traits: "CommonResponse", and "CommonPlayer", when the generic game query function returns a response it returns a pointer to its original response type that implements "CommonResponse". Both common traits require that "as_original()" be implemented, this returns an enum containing a pointer to the original type. Both traits have a concrete method "as_json()" that returns a struct containing data fetched from all of its methods as. This struct implements serde and can hence be serialized as required. The traits require a few other methods be implemented, those being the fields that are common across all types. All other methods have a default None implementation so that each response type only needs to implement methods for fields that it has. * [Game] Implement common traits for JCMP2 response * [Fmt] Run cargo fmt * Fix doctest failing * Run cargo fmt
52 lines
1.5 KiB
Rust
52 lines
1.5 KiB
Rust
//! Game Server Query Library.
|
|
//!
|
|
//! # Usage example:
|
|
//!
|
|
//! ## For a specific game
|
|
//! ```
|
|
//! use gamedig::games::tf2;
|
|
//!
|
|
//! let response = tf2::query(&"127.0.0.1".parse().unwrap(), None); // None is the default port (which is 27015), could also be Some(27015)
|
|
//! match response { // Result type, must check what it is...
|
|
//! Err(error) => println!("Couldn't query, error: {}", error),
|
|
//! Ok(r) => println!("{:#?}", r)
|
|
//! }
|
|
//! ```
|
|
//!
|
|
//! ## Using a game definition
|
|
//! ```
|
|
//! use gamedig::games::{GAMES, query};
|
|
//!
|
|
//! let game = GAMES.get("tf2").unwrap(); // Get a game definition, the full list can be found in src/games/mod.rs
|
|
//! let response = query(game, &"127.0.0.1".parse().unwrap(), None); // None will use the default port
|
|
//! match response {
|
|
//! Err(error) => println!("Couldn't query, error: {}", error),
|
|
//! Ok(r) => println!("{:#?}", r.as_json()),
|
|
//! }
|
|
//! ```
|
|
//!
|
|
//! # Crate features:
|
|
//! Enabled by default: `game_defs`
|
|
//!
|
|
//! `serde` - enables json serialization/deserialization for all response types.
|
|
//! <br> `no_games` - disables the included games support. <br>
|
|
//! `no_services` - disables the included services support. <br>
|
|
//! `game_defs` - Include game definitions for programmatic access (enabled by
|
|
//! default).
|
|
|
|
pub mod errors;
|
|
#[cfg(not(feature = "no_games"))]
|
|
pub mod games;
|
|
pub mod protocols;
|
|
#[cfg(not(feature = "no_services"))]
|
|
pub mod services;
|
|
|
|
mod bufferer;
|
|
mod socket;
|
|
mod utils;
|
|
|
|
pub use errors::*;
|
|
#[cfg(not(feature = "no_games"))]
|
|
pub use games::*;
|
|
#[cfg(not(feature = "no_services"))]
|
|
pub use services::*;
|