1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-20 11:47:46 +00:00

Use split_once in parse_repository_category

This commit is contained in:
Joshua Goins 2025-03-06 16:03:20 -05:00
parent 5c291a4844
commit 75aee9e9d8

View file

@ -201,21 +201,17 @@ impl GameData {
/// Parses a path structure and spits out the corresponding category and repository. /// Parses a path structure and spits out the corresponding category and repository.
fn parse_repository_category(&self, path: &str) -> Option<(&Repository, Category)> { fn parse_repository_category(&self, path: &str) -> Option<(&Repository, Category)> {
let tokens: Vec<&str> = path.split('/').collect(); // TODO: use split_once here let tokens = path.split_once('/')?;
if tokens.len() < 2 { let repository_token = tokens.1;
return None;
}
let repository_token = tokens[1];
for repository in &self.repositories { for repository in &self.repositories {
if repository.name == repository_token { if repository.name == repository_token {
return Some((repository, string_to_category(tokens[0])?)); return Some((repository, string_to_category(tokens.0)?));
} }
} }
Some((&self.repositories[0], string_to_category(tokens[0])?)) Some((&self.repositories[0], string_to_category(tokens.0)?))
} }
fn get_index_filenames(&self, path: &str) -> Option<(Vec<(String, u8)>, Vec<(String, u8)>)> { fn get_index_filenames(&self, path: &str) -> Option<(Vec<(String, u8)>, Vec<(String, u8)>)> {