Skip to content

Commit 056ce2a

Browse files
refactor: put serde functionality behind a feature flag (#36)
* refactor: put `serde` functionality behind a feature flag * ci: check code without default features enabled * docs: instructions for installing without serialization support, and `rgd` example
1 parent c880ccf commit 056ce2a

5 files changed

Lines changed: 36 additions & 7 deletions

File tree

.github/workflows/check.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jobs:
3434
- name: Check
3535
run: cargo check
3636

37+
- name: Check without default features
38+
run: cargo check --no-default-features
39+
3740
- name: Build
3841
run: cargo build --verbose
3942

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lib_game_detector"
3-
version = "0.0.24"
3+
version = "0.0.25"
44
edition = "2021"
55
description = "A Rust library for detecting and parsing data about games installed on the system"
66
readme = "README.md"
@@ -17,7 +17,7 @@ itertools = "0.14"
1717
thiserror = "2.0"
1818
steam_shortcuts_util = "1.1"
1919
walkdir = "2.5"
20-
serde = { version = "1.0", features = ["derive"] }
20+
serde = { version = "1.0", features = ["derive"], optional = true }
2121

2222
[dev-dependencies]
2323
criterion = { version = "0.7", features = ["html_reports"] }
@@ -26,6 +26,7 @@ is-terminal = "0.4"
2626
test-case = "3.3"
2727
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
2828
serde_json = { version = "1.0" }
29+
lib_game_detector = { path = ".", features = ["serde"] }
2930

3031
[[bench]]
3132
name = "criterion"
@@ -36,3 +37,7 @@ harness = false
3637
name = "divan"
3738
path = "benches/divan.rs"
3839
harness = false
40+
41+
[features]
42+
default = ["serde"]
43+
serde = ["dep:serde"]

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ Install with:
2626
cargo add lib_game_detector
2727
```
2828

29+
Support for serialization via `serde`, which is enabled by default, can be disabled
30+
by installing with:
31+
32+
```sh
33+
cargo add lib_game_detector --no-default-features
34+
```
35+
2936
## Usage
3037

3138
```rust
@@ -40,7 +47,8 @@ let all_games_from_steam = detector.get_all_detected_games_from_specific_launche
4047

4148
## Examples
4249

43-
- See [rofi-games](https://github.com/Rolv-Apneseth/rofi-games) for an example which uses this library to find games and their box art to use for displaying in a launcher
50+
- Checkout [rofi-games](https://github.com/Rolv-Apneseth/rofi-games) or [rgd](https://github.com/Rolv-Apneseth/rgd)
51+
to see this library being used to find games and their box art for displaying in a launcher
4452
- Check the [examples folder](https://github.com/Rolv-Apneseth/lib_game_detector/tree/main/examples)
4553

4654
## Currently supported game sources

src/data.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ use std::{
77
sync::Arc,
88
};
99

10+
#[cfg(feature = "serde")]
1011
use serde::{Serialize, Serializer};
1112

1213
use crate::error::GamesParsingError;
1314

1415
/// Serialize a type into a string using the debug output
16+
#[cfg(feature = "serde")]
1517
fn serialize_debug<S, T>(x: &T, s: S) -> Result<S::Ok, S::Error>
1618
where
1719
T: Debug,
@@ -21,7 +23,8 @@ where
2123
}
2224

2325
/// Data structure which defines all relevant data about any particular game
24-
#[derive(Debug, Serialize)]
26+
#[derive(Debug)]
27+
#[cfg_attr(feature = "serde", derive(Serialize))]
2528
pub struct Game {
2629
/// Game title / name.
2730
pub title: String,
@@ -31,12 +34,14 @@ pub struct Game {
3134
pub path_box_art: Option<PathBuf>,
3235
/// Path to the game's root directory (if one was found).
3336
pub path_game_dir: Option<PathBuf>,
37+
3438
/// Command to launch the game.
3539
// NOTE: serialized output can be `sh -c "$launch_command"`
36-
#[serde(serialize_with = "serialize_debug")]
40+
#[cfg_attr(feature = "serde", serde(serialize_with = "serialize_debug"))]
3741
pub launch_command: Command,
42+
3843
/// Game detection source.
39-
#[serde(serialize_with = "serialize_debug")]
44+
#[cfg_attr(feature = "serde", serde(serialize_with = "serialize_debug"))]
4045
pub source: SupportedLaunchers,
4146
}
4247

src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
//! cargo add lib_game_detector
2323
//! ```
2424
//!
25+
//! Support for serialization via `serde`, which is enabled by default, can be disabled
26+
//! by installing with:
27+
//!
28+
//! ```sh
29+
//! cargo add lib_game_detector --no-default-features
30+
//! ```
31+
//!
2532
//! # Usage
2633
//!
2734
//! ```rust
@@ -36,7 +43,8 @@
3643
//!
3744
//! # Examples
3845
//!
39-
//! - See [rofi-games](https://github.com/Rolv-Apneseth/rofi-games) for an example which uses this library to find games and their box art to use for displaying in a launcher
46+
//! - Checkout [rofi-games](https://github.com/Rolv-Apneseth/rofi-games) or [rgd](https://github.com/Rolv-Apneseth/rgd)
47+
//! to see this library being used to find games and their box art for displaying in a launcher
4048
//! - Check the [examples folder](https://github.com/Rolv-Apneseth/lib_game_detector/tree/main/examples)
4149
//!
4250
//! # Currently supported game sources

0 commit comments

Comments
 (0)