lix-installer/src/action/mod.rs

43 lines
1.2 KiB
Rust
Raw Normal View History

2022-10-28 16:29:15 +00:00
pub mod common;
pub mod darwin;
pub mod linux;
2022-09-15 19:11:46 +00:00
use serde::{Deserialize, Serialize};
#[async_trait::async_trait]
#[typetag::serde(tag = "action")]
pub trait Action: Send + Sync + std::fmt::Debug + dyn_clone::DynClone {
2022-09-27 19:05:24 +00:00
fn describe_execute(&self) -> Vec<ActionDescription>;
fn describe_revert(&self) -> Vec<ActionDescription>;
2022-09-26 21:07:53 +00:00
2022-10-28 21:15:33 +00:00
// They should also have an `async fn plan(args...) -> Result<ActionState<Self>, Box<dyn std::error::Error + Send + Sync>>;`
async fn execute(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
async fn revert(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
2022-09-15 19:11:46 +00:00
}
dyn_clone::clone_trait_object!(Action);
2022-09-26 23:14:25 +00:00
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub enum ActionState {
Completed,
2022-09-28 20:20:11 +00:00
// Only applicable to meta-actions that start multiple sub-actions.
Progress,
2022-09-26 23:14:25 +00:00
Uncompleted,
2022-09-15 19:11:46 +00:00
}
2022-09-14 22:18:13 +00:00
2022-09-15 17:29:22 +00:00
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
pub struct ActionDescription {
pub description: String,
pub explanation: Vec<String>,
}
impl ActionDescription {
fn new(description: String, explanation: Vec<String>) -> Self {
2022-09-15 19:11:46 +00:00
Self {
description,
explanation,
}
2022-09-15 17:29:22 +00:00
}
}