Skip to content

Commit

Permalink
Merge pull request #1277 from Integral-Tech/destruct-tuple
Browse files Browse the repository at this point in the history
refactor: destruct tuples to enhance readability
  • Loading branch information
Morganamilo authored Dec 27, 2024
2 parents c9c4a23 + 073dffa commit bb917db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
9 changes: 3 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ impl Config {
}

if self.repos != LocalRepos::None {
let repos = repo::repo_aur_dbs(self).1;
let (_, repos) = repo::repo_aur_dbs(self);

if repos.is_empty() {
bail!(
Expand Down Expand Up @@ -1170,10 +1170,7 @@ pub fn version() {
println!(" - libalpm v{}", alpm::version());
}

fn question(question: AnyQuestion, data: &mut (bool, Colors)) {
let no_confirm = data.0;
let c = data.1;

fn question(question: AnyQuestion, (no_confirm, c): &mut (bool, Colors)) {
match question.question() {
Question::SelectProvider(mut question) => {
let providers = question.providers();
Expand Down Expand Up @@ -1203,7 +1200,7 @@ fn question(question: AnyQuestion, data: &mut (bool, Colors)) {
print!("{}) {} ", n + 1, pkg.name());
}

let index = get_provider(len, no_confirm);
let index = get_provider(len, *no_confirm);
question.set_index(index as i32);
}
Question::InstallIgnorepkg(mut question) => {
Expand Down
6 changes: 3 additions & 3 deletions src/devel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub async fn gendb(config: &mut Config) -> Result<()> {
let pkgs = db.pkgs().iter().map(|p| p.name()).collect::<Vec<_>>();
let ignore = &config.ignore;

let mut aur = split_repo_aur_pkgs(config, &pkgs).1;
let (_, mut aur) = split_repo_aur_pkgs(config, &pkgs);
let mut devel_info = load_devel_info(config)?.unwrap_or_default();

aur.retain(|pkg| {
Expand Down Expand Up @@ -321,11 +321,11 @@ fn parse_url(source: &str) -> Option<(String, &'_ str, Option<&'_ str>)> {

let mut split = rest.splitn(2, '#');
let remote = split.next().unwrap();
let remote = remote.split_once('?').map_or(remote, |x| x.0);
let remote = remote.split_once('?').map_or(remote, |(x, _)| x);
let remote = format!("{}://{}", protocol, remote);

let branch = if let Some(fragment) = split.next() {
let fragment = fragment.split_once('?').map_or(fragment, |x| x.0);
let fragment = fragment.split_once('?').map_or(fragment, |(x, _)| x);
let mut split = fragment.splitn(2, '=');
let frag_type = split.next().unwrap();

Expand Down
20 changes: 10 additions & 10 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,9 @@ impl Installer {
repo::add(config, path, &name, &paths)?;
repo::refresh(config, &[name])?;
} else {
let path = repo.1;
repo::add(config, path, repo.0, &paths)?;
repo::refresh(config, &[repo.0])?;
let (name, path) = repo;
repo::add(config, path, name, &paths)?;
repo::refresh(config, &[name])?;
}
if let Some(info) = self.new_devel_info.info.remove(base.package_base()) {
self.devel_info
Expand Down Expand Up @@ -852,7 +852,7 @@ impl Installer {
self.failed.push(base.clone());
let repo_server = repo_server
.as_ref()
.map(|rs| (rs.0.as_str(), rs.1.as_str()));
.map(|(name, file)| (name.as_str(), file.as_str()));

let err = self.build_install_pkgbuild(config, base, repo_server);

Expand Down Expand Up @@ -965,9 +965,9 @@ impl Installer {
repo: Some(config.aur_namespace()),
pkg: p,
}));
targets.extend(self.upgrades.pkgbuild_keep.iter().map(|p| Targ {
repo: Some(&p.0),
pkg: &p.1,
targets.extend(self.upgrades.pkgbuild_keep.iter().map(|(repo, pkg)| Targ {
repo: Some(repo),
pkg,
}));

targets.extend(self.upgrades.repo_keep.iter().map(Targ::from));
Expand Down Expand Up @@ -1235,8 +1235,8 @@ impl Installer {
self.remove_make.extend(
actions
.iter_pkgbuilds()
.filter(|p| p.1.make)
.map(|p| p.1.pkg.pkgname.clone()),
.filter(|(_, p)| p.make)
.map(|(_, p)| p.pkg.pkgname.clone()),
);
}

Expand Down Expand Up @@ -1843,7 +1843,7 @@ fn chroot(config: &Config) -> Chroot {

fn trim_dep_ver(dep: &str, trim: bool) -> &str {
if trim {
dep.split_once(is_ver_char).map_or(dep, |x| x.0)
dep.split_once(is_ver_char).map_or(dep, |(x, _)| x)
} else {
dep
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ pub async fn run<S: AsRef<str>>(args: &[S]) -> i32 {
let mut config = match Config::new() {
Ok(config) => config,
Err(err) => {
let code = if let Some(e) = err.downcast_ref::<install::Status>() {
e.0
let code = if let Some(&install::Status(e)) = err.downcast_ref() {
e
} else {
1
};
Expand All @@ -146,8 +146,8 @@ pub async fn run<S: AsRef<str>>(args: &[S]) -> i32 {

match run2(&mut config, args).await {
Err(err) => {
let code = if let Some(e) = err.downcast_ref::<install::Status>() {
e.0
let code = if let Some(&install::Status(e)) = err.downcast_ref() {
e
} else {
1
};
Expand Down

0 comments on commit bb917db

Please sign in to comment.