(path: impl AsRef<Path>)
| 38 | } |
| 39 | |
| 40 | pub async fn read_json<T>(path: impl AsRef<Path>) -> Result<T> |
| 41 | where |
| 42 | T: DeserializeOwned, |
| 43 | { |
| 44 | let path = path.as_ref(); |
| 45 | if !path.exists() { |
| 46 | return Err(Error::FileNotFound(path.display().to_string())); |
| 47 | } |
| 48 | |
| 49 | let content = tokio::fs::read_to_string(path).await?; |
| 50 | let data: T = serde_json::from_str(&content)?; |
| 51 | Ok(data) |
| 52 | } |