Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 2 additions & 33 deletions crates/lantern-app/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{path::PathBuf, sync::Arc};

use lantern_domain::{DriveState, ProfileId, SessionId, SlaveId};
use lantern_profile::ValidatedDeviceProfile;
use thiserror::Error;

use crate::{
AuditHealth, Authorization, BackupCaptureRequest, BackupRestoreAction, BackupRestoreEffect,
Expand All @@ -18,9 +17,11 @@ use crate::{
mod connection;
mod faults;
mod monitoring;
mod runtime;
mod state;
mod view;

pub use runtime::{ApplicationEffectError, ApplicationRuntime, EffectRunner};
use state::{ApplicationMonitoringState, ApplicationParameterState};
use view::port_label;
pub use view::{
Expand Down Expand Up @@ -625,38 +626,6 @@ pub enum ApplicationEffect {
Session(SessionEffect),
}

#[derive(Debug, Error)]
#[error("application effect failed: {0}")]
pub struct ApplicationEffectError(pub String);

pub trait EffectRunner {
fn execute(&mut self, effect: ApplicationEffect) -> Result<(), ApplicationEffectError>;
}

pub struct ApplicationRuntime<R> {
state: ApplicationState,
runner: R,
}

impl<R: EffectRunner> ApplicationRuntime<R> {
#[must_use]
pub fn new(state: ApplicationState, runner: R) -> Self {
Self { state, runner }
}

pub fn dispatch(&mut self, action: ApplicationAction) -> Result<(), ApplicationEffectError> {
for effect in self.state.reduce(action) {
self.runner.execute(effect)?;
}
Ok(())
}

#[must_use]
pub const fn state(&self) -> &ApplicationState {
&self.state
}
}

#[cfg(test)]
mod tests {
use std::{path::PathBuf, sync::Arc};
Expand Down
35 changes: 35 additions & 0 deletions crates/lantern-app/src/application/runtime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use thiserror::Error;

use super::{ApplicationAction, ApplicationEffect, ApplicationState};

#[derive(Debug, Error)]
#[error("application effect failed: {0}")]
pub struct ApplicationEffectError(pub String);

pub trait EffectRunner {
fn execute(&mut self, effect: ApplicationEffect) -> Result<(), ApplicationEffectError>;
}

pub struct ApplicationRuntime<R> {
state: ApplicationState,
runner: R,
}

impl<R: EffectRunner> ApplicationRuntime<R> {
#[must_use]
pub fn new(state: ApplicationState, runner: R) -> Self {
Self { state, runner }
}

pub fn dispatch(&mut self, action: ApplicationAction) -> Result<(), ApplicationEffectError> {
for effect in self.state.reduce(action) {
self.runner.execute(effect)?;
}
Ok(())
}

#[must_use]
pub const fn state(&self) -> &ApplicationState {
&self.state
}
}
Loading