From c7596f62b75981f8042d7d67194b3fd75be28186 Mon Sep 17 00:00:00 2001 From: innocentzero Date: Mon, 25 Mar 2024 04:28:06 +0530 Subject: [PATCH] refact(rustup): Use anyhow::Error Remove repeated instances of anyhow::Error and make the code sparser. Signed-off-by: innocentzero --- .../pacdef_core/src/backend/actual/rustup.rs | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/crates/pacdef_core/src/backend/actual/rustup.rs b/crates/pacdef_core/src/backend/actual/rustup.rs index 875ce93..5140314 100644 --- a/crates/pacdef_core/src/backend/actual/rustup.rs +++ b/crates/pacdef_core/src/backend/actual/rustup.rs @@ -1,11 +1,11 @@ use crate::backend::backend_trait::{Backend, Switches, Text}; use crate::backend::macros::impl_backend_constants; use crate::{Group, Package}; -use anyhow::Context; +use anyhow::{Context, Result}; use core::panic; use std::collections::HashSet; use std::os::unix::process::ExitStatusExt; -use std::process::Command; +use std::process::{Command, ExitStatus}; #[derive(Debug, Clone)] pub struct Rustup { @@ -26,7 +26,7 @@ const SUPPORTS_AS_DEPENDENCY: bool = false; impl Backend for Rustup { impl_backend_constants!(); - fn get_all_installed_packages(&self) -> anyhow::Result> { + fn get_all_installed_packages(&self) -> Result> { let mut toolchains_vec = self .run_toolchain_command(self.get_info_switches("toolchain")) .context("Getting installed toolchains")?; @@ -46,22 +46,16 @@ impl Backend for Rustup { Ok(toolchains) } - fn get_explicitly_installed_packages(&self) -> anyhow::Result> { + fn get_explicitly_installed_packages(&self) -> Result> { self.get_all_installed_packages() .context("Getting all installed packages") } - fn make_dependency(&self, _: &[Package]) -> anyhow::Result { + fn make_dependency(&self, _: &[Package]) -> Result { panic!("Not supported by {}", self.get_binary()) } - fn install_packages( - &self, - packages: &[Package], - _: bool, - ) -> anyhow::Result { - let mut result: anyhow::Result = - Ok(std::process::ExitStatus::from_raw(0)); + fn install_packages(&self, packages: &[Package], _: bool) -> Result { for p in packages { let repo = p .repo @@ -168,7 +162,7 @@ impl Rustup { &self, args: &[&str], toolchains: &mut Vec, - ) -> Result, anyhow::Error> { + ) -> Result> { let mut val = Vec::new(); for toolchain in toolchains { let mut cmd = Command::new(self.get_binary()); @@ -194,7 +188,7 @@ impl Rustup { } Ok(val) } - fn run_toolchain_command(&self, args: &[&str]) -> Result, anyhow::Error> { + fn run_toolchain_command(&self, args: &[&str]) -> Result> { let mut cmd = Command::new(self.get_binary()); cmd.args(args); let output = String::from_utf8(cmd.output()?.stdout)?;