major overhaul of Backend from dynamic to static dispatch using an big enum

This commit is contained in:
ripytide
2024-04-22 14:08:53 +01:00
parent 636a7a02ec
commit df5b229d23
36 changed files with 382 additions and 590 deletions
+5 -6
View File
@@ -1,7 +1,6 @@
use std::rc::Rc;
use crate::backend::Backend;
use crate::{Group, Package};
use crate::{backend::AnyBackend, Group, Package};
use super::strategy::Strategy;
@@ -26,7 +25,7 @@ pub(super) enum ReviewIntention {
#[derive(Debug)]
pub(super) struct ReviewsPerBackend {
items: Vec<(Box<dyn Backend>, Vec<ReviewAction>)>,
items: Vec<(AnyBackend, Vec<ReviewAction>)>,
}
impl ReviewsPerBackend {
@@ -38,7 +37,7 @@ impl ReviewsPerBackend {
self.items.iter().all(|(_, vec)| vec.is_empty())
}
pub(super) fn push(&mut self, value: (Box<dyn Backend>, Vec<ReviewAction>)) {
pub(super) fn push(&mut self, value: (AnyBackend, Vec<ReviewAction>)) {
self.items.push(value);
}
@@ -77,9 +76,9 @@ impl ReviewsPerBackend {
}
impl IntoIterator for ReviewsPerBackend {
type Item = (Box<dyn Backend>, Vec<ReviewAction>);
type Item = (AnyBackend, Vec<ReviewAction>);
type IntoIter = std::vec::IntoIter<(Box<dyn Backend>, Vec<ReviewAction>)>;
type IntoIter = std::vec::IntoIter<(AnyBackend, Vec<ReviewAction>)>;
fn into_iter(self) -> Self::IntoIter {
self.items.into_iter()
+5 -5
View File
@@ -6,7 +6,8 @@ use std::rc::Rc;
use anyhow::Result;
use crate::backend::{Backend, ToDoPerBackend};
use crate::backend::backend_trait::Backend;
use crate::backend::todo_per_backend::ToDoPerBackend;
use crate::ui::{get_user_confirmation, read_single_char_from_terminal};
use crate::{Group, Package};
@@ -27,11 +28,11 @@ pub fn review(
return Ok(());
}
'outer: for (backend, packages) in todo_per_backend.into_iter() {
'outer: for (backend, packages) in todo_per_backend {
let mut actions = vec![];
for package in packages {
println!("{}: {package}", backend.get_section());
match get_action_for_package(package, &groups, &mut actions, &*backend)? {
match get_action_for_package(package, &groups, &mut actions, &backend)? {
ContinueWithReview::Yes => continue,
ContinueWithReview::No => return Ok(()),
ContinueWithReview::NoAndApply => {
@@ -161,9 +162,8 @@ fn print_enumerated_groups(groups: &[Rc<Group>]) {
}
}
#[allow(clippy::as_conversions)] // this cannot introduce errors for any reasonably sized numbers.
fn get_amount_of_digits_for_number(number: usize) -> usize {
(number as f64).log10().trunc() as usize + 1
number.to_string().len()
}
fn ask_group(groups: &[Rc<Group>]) -> Result<Option<Rc<Group>>> {
+6 -4
View File
@@ -2,12 +2,14 @@ use std::rc::Rc;
use anyhow::Result;
use crate::backend::Backend;
use crate::{Group, Package};
use crate::{
backend::{backend_trait::Backend, AnyBackend},
Group, Package,
};
#[derive(Debug)]
pub(super) struct Strategy {
backend: Box<dyn Backend>,
backend: AnyBackend,
delete: Vec<Package>,
as_dependency: Vec<Package>,
assign_group: Vec<(Package, Rc<Group>)>,
@@ -15,7 +17,7 @@ pub(super) struct Strategy {
impl Strategy {
pub(super) fn new(
backend: Box<dyn Backend>,
backend: AnyBackend,
delete: Vec<Package>,
as_dependency: Vec<Package>,
assign_group: Vec<(Package, Rc<Group>)>,