Added accounts

This commit is contained in:
2026-07-24 23:31:21 +02:00
parent cf4387c604
commit db2f476928
5 changed files with 66 additions and 19 deletions
+38
View File
@@ -0,0 +1,38 @@
#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
pub struct WatchList {
pub symbols: Vec<String>,
}
#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
pub struct Config {
pub watchlist: WatchList,
}
impl Config {
pub async fn new() -> tokio::io::Result<Self> {
let path = crate::store::pulse_config_file()?;
if !path.exists() {
let default = Self::default();
tokio::fs::create_dir_all(path.parent().unwrap()).await?;
tokio::fs::write(&path, default.to_string()?).await?;
return Ok(default);
}
let output = tokio::fs::read_to_string(path).await?;
Self::from_str(&output)
}
pub fn from_str(s: &str) -> tokio::io::Result<Self> {
toml::from_str(s)
.map_err(|v| tokio::io::Error::new(std::io::ErrorKind::InvalidInput, v.to_string()))
}
pub fn to_string(&self) -> tokio::io::Result<String> {
toml::to_string(self)
.map_err(|v| tokio::io::Error::new(std::io::ErrorKind::Other, v.to_string()))
}
}