-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(context): reimplement context as an kv store
- Loading branch information
Showing
9 changed files
with
320 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,15 @@ | ||
use crate::config::Config; | ||
use anyhow::{anyhow, Error}; | ||
use mfm_machine::state::context::Context; | ||
use serde_derive::{Deserialize, Serialize}; | ||
use serde_json::Value; | ||
|
||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum ConfigSource { | ||
TomlFile(String), | ||
} | ||
|
||
impl Context for ConfigSource { | ||
fn read(&self) -> Result<Value, Error> { | ||
serde_json::to_value(self).map_err(|e| anyhow!(e)) | ||
} | ||
|
||
fn write(&mut self, _: &Value) -> Result<(), Error> { | ||
// do nothing | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||
pub struct ReadConfig { | ||
pub config_source: ConfigSource, | ||
pub config: Config, | ||
} | ||
pub const READ_CONFIG: &str = "read_config"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.