-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
114 additions
and
200 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
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
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,2 +1,2 @@ | ||
pub mod get_node_by_path; | ||
mod storage; | ||
pub mod storage; |
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,15 +1,13 @@ | ||
#[cfg(feature = "storage")] | ||
#![cfg(feature = "storage")] | ||
use crate::Node; | ||
|
||
#[cfg(feature = "storage")] | ||
pub fn get_node_by_path(data_path: &'static str, path: &str) -> Result<Node, std::io::Error> { | ||
let fs_path = format!("{}/{}/info.json", data_path, path); | ||
let info = std::fs::read_to_string(fs_path)?; | ||
let Ok(node) = serde_json::from_str::<Node>(info.as_str()) else { | ||
return Err(std::io::Error::new( | ||
std::io::ErrorKind::Other, | ||
"json was not deserialized", | ||
)); | ||
}; | ||
Ok(node) | ||
pub enum StorageError { | ||
Io(std::io::Error), | ||
Json(serde_json::Error), | ||
} | ||
|
||
pub fn get_node_by_path(path: impl AsRef<std::path::Path>) -> Result<Node, StorageError> { | ||
let json_file_path = path.as_ref().join("info.json"); | ||
let json_file_content = std::fs::read_to_string(json_file_path).map_err(StorageError::Io)?; | ||
serde_json::from_str::<Node>(json_file_content.as_str()).map_err(StorageError::Json) | ||
} |
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,8 +1,9 @@ | ||
#[cfg(feature = "const")] | ||
mod _auto_generated; | ||
|
||
mod api; | ||
mod node; | ||
|
||
pub use api::get_node_by_path::get_node_by_path; | ||
#[cfg(feature = "storage")] | ||
pub use api::storage::StorageError; | ||
pub use node::model::{Node, NodeName, NodeTerms, NodeType}; |
Oops, something went wrong.