Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmicHorrorDev committed Dec 16, 2023
1 parent b730e9c commit b0e65b7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub struct App {
pub app_id: u32,
/// The name of the installation directory of this Steam app e.g. `"GarrysMod"`
///
/// If you're trying to get the app's installation directory then take a look at
/// [`Library::resolve_app_dir()`][crate::Library::resolve_app_dir]
/// If you're trying to get the app's installation directory then take a look at
/// [`Library::resolve_app_dir()`][crate::Library::resolve_app_dir]
#[serde(rename = "installdir")]
pub install_dir: String,
/// The store name of the Steam app
Expand Down
21 changes: 12 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,26 @@ impl SteamDir {
/// # Example
/// ```
/// # let temp_steam_dir = steamlocate::tests::helpers::expect_test_env();
/// # let steam_dir = temp_steam_dir.steam_dir();
/// # /*
/// let steam_dir = SteamDir::locate()?;
/// # */
/// const WARFRAME: u32 = 230_410;
/// # let steam_dir = temp_steam_dir.steam_dir();
/// # /*
/// let steam_dir = SteamDir::locate()?;
/// # */
/// const WARFRAME: u32 = 230_410;
/// let (warframe, library) = steam_dir.find_app(WARFRAME)?.unwrap();
/// assert_eq!(warframe.app_id, WARFRAME);
/// assert!(library.app_ids().contains(&warframe.app_id));
/// # Ok::<_, steamlocate::tests::TestError>(())
/// assert!(library.app_ids().contains(&warframe.app_id));
/// # Ok::<_, steamlocate::tests::TestError>(())
/// ```
pub fn find_app(&self, app_id: u32) -> Result<Option<(App, Library)>> {
// Search for the `app_id` in each library
match self.libraries() {
Err(e) => Err(e),
Ok(libraries) => libraries
.filter_map(|library| library.ok())
.find_map(|lib| lib.app(app_id).map(|maybe_app| maybe_app.map(|app| (app, lib))))
.find_map(|lib| {
lib.app(app_id)
.map(|maybe_app| maybe_app.map(|app| (app, lib)))
})
.transpose(),
}
}
Expand All @@ -215,7 +218,7 @@ impl SteamDir {
shortcut::Iter::new(&self.path)
}

// TODO: rename to `from_dir()` and make consitent with similar constructors on other structs
// TODO: rename to `from_dir()` and make consitent with similar constructors on other structs
pub fn from_steam_dir(path: &Path) -> Result<SteamDir> {
if !path.is_dir() {
return Err(Error::validation(ValidationError::missing_dir()));
Expand Down
36 changes: 18 additions & 18 deletions src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,24 @@ impl Library {
app::Iter::new(self)
}

/// Resolves the theoretical installation directory for the given `app`
///
/// This is an unvalidated path, so it's up to you to call this with an `app` that's in this
/// library
///
/// # Example
///
/// ```
/// # use std::path::Path;
/// # let temp_steam_dir = steamlocate::tests::helpers::expect_test_env();
/// # let steam_dir = temp_steam_dir.steam_dir();
/// const GRAVEYARD_KEEPER: u32 = 599_140;
/// let (graveyard_keeper, library) = steam_dir.find_app(GRAVEYARD_KEEPER)?.unwrap();
/// let app_dir = library.resolve_app_dir(&graveyard_keeper);
/// let expected_rel_path = Path::new("steamapps").join("common").join("Graveyard Keeper");
/// assert!(app_dir.ends_with(expected_rel_path));
/// # Ok::<_, steamlocate::tests::TestError>(())
/// ```
/// Resolves the theoretical installation directory for the given `app`
///
/// This is an unvalidated path, so it's up to you to call this with an `app` that's in this
/// library
///
/// # Example
///
/// ```
/// # use std::path::Path;
/// # let temp_steam_dir = steamlocate::tests::helpers::expect_test_env();
/// # let steam_dir = temp_steam_dir.steam_dir();
/// const GRAVEYARD_KEEPER: u32 = 599_140;
/// let (graveyard_keeper, library) = steam_dir.find_app(GRAVEYARD_KEEPER)?.unwrap();
/// let app_dir = library.resolve_app_dir(&graveyard_keeper);
/// let expected_rel_path = Path::new("steamapps").join("common").join("Graveyard Keeper");
/// assert!(app_dir.ends_with(expected_rel_path));
/// # Ok::<_, steamlocate::tests::TestError>(())
/// ```
pub fn resolve_app_dir(&self, app: &App) -> PathBuf {
self.path
.join("steamapps")
Expand Down
19 changes: 11 additions & 8 deletions src/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use serde::Serialize;
pub fn expect_test_env() -> TempSteamDir {
TempSteamDir::builder()
.app(SampleApp::GarrysMod.into())
.app(SampleApp::Warframe.into())
.app(SampleApp::Warframe.into())
.library(SampleApp::GraveyardKeeper.try_into().unwrap())
.finish()
.unwrap()
Expand Down Expand Up @@ -258,7 +258,7 @@ impl AppFile {
pub enum SampleApp {
GarrysMod,
GraveyardKeeper,
Warframe,
Warframe,
}

impl SampleApp {
Expand Down Expand Up @@ -286,11 +286,11 @@ impl SampleApp {
"Graveyard Keeper",
include_str!("../../tests/assets/appmanifest_599140.acf"),
),
Self::Warframe => (
230_410,
"Warframe",
include_str!("../../tests/assets/appmanifest_230410.acf"),
),
Self::Warframe => (
230_410,
"Warframe",
include_str!("../../tests/assets/appmanifest_230410.acf"),
),
}
}
}
Expand All @@ -304,7 +304,10 @@ mod test {
fn sanity() -> TestResult {
let tmp_steam_dir = TempSteamDir::try_from(SampleApp::GarrysMod)?;
let steam_dir = tmp_steam_dir.steam_dir();
assert!(steam_dir.find_app(SampleApp::GarrysMod.id()).unwrap().is_some());
assert!(steam_dir
.find_app(SampleApp::GarrysMod.id())
.unwrap()
.is_some());

Ok(())
}
Expand Down

0 comments on commit b0e65b7

Please sign in to comment.