From 1ad93cec9695aebae6c4329b1f7a166e8d8e63fa Mon Sep 17 00:00:00 2001 From: innocentzero Date: Wed, 28 Feb 2024 00:39:31 +0530 Subject: [PATCH] refact(package.rs): Expose repo field publicly Expose repo field publicly for install_packages in rustup backend to utilize, otherwise very ugly hacks need to be used to handle toolchains and components. Signed-off-by: innocentzero --- crates/pacdef_core/src/grouping/package.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/pacdef_core/src/grouping/package.rs b/crates/pacdef_core/src/grouping/package.rs index f10b756..ed12a76 100644 --- a/crates/pacdef_core/src/grouping/package.rs +++ b/crates/pacdef_core/src/grouping/package.rs @@ -6,7 +6,7 @@ use std::hash::Hash; #[derive(Debug, Eq, PartialOrd, Ord, Clone)] pub struct Package { pub(crate) name: String, - repo: Option, + pub(crate) repo: Option, } fn remove_comment_and_trim_whitespace(s: &str) -> &str { @@ -41,10 +41,11 @@ impl Package { /// /// Panics if `string` is empty. fn split_into_name_and_repo(string: &str) -> (String, Option) { - let mut iter = string.split('/').rev(); - let name = iter.next().expect("we checked that earlier").to_string(); - let repo = iter.next().map(|s| s.to_string()); - (name, repo) + if let Some((before, after)) = string.split_once('/') { + (after.to_string(), Some(before.to_string())) + } else { + (string.to_string(), None) + } } /// Try to parse a string (from a line in a group file) and return a package.