Skip to content

Commit

Permalink
Update fs.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Umatriz committed Jul 13, 2024
1 parent f93f986 commit c527d33
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions crates/nomi-core/src/fs.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::path::Path;

use anyhow::anyhow;
use serde::{de::DeserializeOwned, Serialize};
use tokio::io::AsyncWriteExt;
use tracing::Level;

#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()))]
#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()), err)]
pub async fn write_toml_config<T>(data: &T, path: impl AsRef<Path>) -> anyhow::Result<()>
where
T: Serialize + ?Sized,
Expand All @@ -19,7 +17,7 @@ where
Ok(())
}

#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()))]
#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()), err)]
pub async fn read_toml_config<T>(path: impl AsRef<Path>) -> anyhow::Result<T>
where
T: DeserializeOwned + ?Sized,
Expand All @@ -34,7 +32,7 @@ where
Ok(body)
}

#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()))]
#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()), err)]
pub fn read_toml_config_sync<T>(path: impl AsRef<Path>) -> anyhow::Result<T>
where
T: DeserializeOwned + ?Sized,
Expand All @@ -43,7 +41,7 @@ where
runtime.block_on(read_toml_config::<T>(path))
}

#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()))]
#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()), err)]
pub fn write_toml_config_sync<T>(data: &T, path: impl AsRef<Path>) -> anyhow::Result<()>
where
T: Serialize + ?Sized,
Expand All @@ -52,6 +50,7 @@ where
runtime.block_on(write_toml_config::<T>(data, path))
}

#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()), err)]
pub async fn read_json_config<T>(path: impl AsRef<Path>) -> anyhow::Result<T>
where
T: DeserializeOwned + ?Sized,
Expand All @@ -61,7 +60,7 @@ where
Ok(serde_json::from_str::<T>(&s)?)
}

#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()), level = Level::DEBUG)]
#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()), err)]
pub async fn write_json_config<T>(data: &T, path: impl AsRef<Path>) -> anyhow::Result<()>
where
T: Serialize + ?Sized,
Expand All @@ -76,7 +75,7 @@ where
Ok(())
}

#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()))]
#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()), err)]
pub async fn write_to_file(data: &[u8], path: impl AsRef<Path>) -> anyhow::Result<()> {
let path = path.as_ref();
if let Some(dir) = path.parent() {
Expand Down

0 comments on commit c527d33

Please sign in to comment.