ModuleSetup returns a concrete type via a generic type parameter
This commit is contained in:
parent
863f48604c
commit
7019a0a071
|
@ -137,6 +137,6 @@ impl<Condition: Into<Option<SomeCondition>>> CommandBuilder<Cmd, Condition> {
|
|||
}
|
||||
|
||||
pub fn run(self) -> Result<CommandStatus, CommandError> {
|
||||
self.build().run().into()
|
||||
CommandModule::run(self.build()).into()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,9 +30,9 @@ impl CommandModule {
|
|||
}
|
||||
}
|
||||
|
||||
impl ModuleSetup<CommandArgs, CommandStatus, CommandError> for CommandModule {
|
||||
fn with_facts(self, _facts: &Facts) -> Box<dyn Module<CommandArgs, CommandStatus, CommandError>> {
|
||||
Box::new(self)
|
||||
impl ModuleSetup<CommandModule, CommandArgs, CommandStatus, CommandError> for CommandModule {
|
||||
fn with_facts(self, _facts: &Facts) -> CommandModule {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,12 +69,12 @@ impl PlaybookRun {
|
|||
println!("{}", serde_json::to_string_pretty(&self).unwrap());
|
||||
}
|
||||
|
||||
pub fn run<MS: ModuleSetup<A, S, E>, A: Serialize, S: Serialize, E: Serialize>(&mut self, cmd: MS) -> Result<S, E> {
|
||||
pub fn run<T: Module<A, S, E>, MS: ModuleSetup<T, A, S, E>, A: Serialize, S: Serialize, E: Serialize>(&mut self, cmd: MS) -> Result<S, E> {
|
||||
let module = cmd.with_facts(&self.facts);
|
||||
self.run_inner(module)
|
||||
}
|
||||
|
||||
pub fn run_inner<A: Serialize, S: Serialize, E: Serialize>(&mut self, cmd: Box<dyn Module<A, S, E>>) -> Result<S, E> {
|
||||
pub fn run_inner<T: Module<A, S, E>, A: Serialize, S: Serialize, E: Serialize>(&mut self, cmd: T) -> Result<S, E> {
|
||||
// TODO: Check conditions for skip
|
||||
|
||||
let module_name = cmd.module_name().to_string();
|
||||
|
@ -108,10 +108,10 @@ impl PlaybookRun {
|
|||
// }
|
||||
|
||||
/// A trait for modules to be run in the context of a playbook, by gathering facts
|
||||
pub trait ModuleSetup<A, S, E> {
|
||||
pub trait ModuleSetup<T: Module<A, S, E>, A: Serialize, S: Serialize, E: Serialize> {
|
||||
// type module: Module<A, S, E>;
|
||||
|
||||
fn with_facts(self, facts: &Facts) -> Box<dyn Module<A, S, E>>;
|
||||
fn with_facts(self, facts: &Facts) -> T;
|
||||
}
|
||||
|
||||
/// A Module takes some arguments which can be serialized back to the playbook run, and can be run to produce
|
||||
|
|
|
@ -53,8 +53,8 @@ impl Module<PackageArgs, (), PackageError> for PackageModule<Box<dyn SpecificPac
|
|||
}
|
||||
}
|
||||
|
||||
impl ModuleSetup<PackageArgs, (), PackageError> for PackageModule<NoManager> {
|
||||
fn with_facts(self, facts: &Facts) -> Box<dyn Module<PackageArgs, (), PackageError>> {
|
||||
impl ModuleSetup<PackageModule<Box<dyn SpecificPackageManager>>, PackageArgs, (), PackageError> for PackageModule<NoManager> {
|
||||
fn with_facts(self, facts: &Facts) -> PackageModule<Box<dyn SpecificPackageManager>> {
|
||||
let Self { args, .. } = self;
|
||||
|
||||
let manager: Box<dyn SpecificPackageManager> = match facts.os.family() {
|
||||
|
@ -62,10 +62,10 @@ impl ModuleSetup<PackageArgs, (), PackageError> for PackageModule<NoManager> {
|
|||
OsFamily::Archlinux => Box::new(ArchlinuxPackageManager),
|
||||
};
|
||||
|
||||
Box::new(PackageModule {
|
||||
PackageModule {
|
||||
args,
|
||||
manager,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user