-
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
6 changed files
with
117 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod get_node_by_path; | ||
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#[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) | ||
} |
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,4 +1,6 @@ | ||
#[cfg(feature = "const")] | ||
mod _auto_generated; | ||
|
||
mod api; | ||
mod node; | ||
|
||
|
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,43 +1,74 @@ | ||
#[cfg(feature = "serde_derive")] | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[cfg(feature = "const")] | ||
#[derive(Debug, PartialEq)] | ||
#[cfg_attr(feature = "serde_derive", derive(Serialize, Deserialize))] | ||
pub struct NodeName<'a> { | ||
#[cfg(feature = "const")] | ||
pub ar: &'a str, | ||
#[cfg(feature = "const")] | ||
pub en: &'a str, | ||
#[cfg(feature = "const")] | ||
pub fr: &'a str, | ||
} | ||
|
||
#[cfg(feature = "storage")] | ||
#[derive(Debug, PartialEq)] | ||
#[cfg_attr(feature = "serde_derive", derive(Serialize, Deserialize))] | ||
pub struct NodeName { | ||
pub ar: String, | ||
pub en: String, | ||
pub fr: String, | ||
} | ||
|
||
#[cfg(any(feature = "const", feature = "storage"))] | ||
#[derive(Debug, PartialEq)] | ||
#[cfg_attr( | ||
feature = "serde_derive", | ||
derive(Serialize, Deserialize), | ||
serde(tag = "type") | ||
)] | ||
pub enum NodeType { | ||
#[cfg_attr(feature = "serde_derive", serde(rename = "UNIVERSITY"))] | ||
University, | ||
#[cfg_attr(feature = "serde_derive", serde(rename = "ACADEMY"))] | ||
Academy, | ||
#[cfg_attr(feature = "serde_derive", serde(rename = "PRIVATE_SCHOOL"))] | ||
PrivateSchool, | ||
#[cfg_attr(feature = "serde_derive", serde(rename = "INSTITUTE"))] | ||
Institute, | ||
#[cfg_attr(feature = "serde_derive", serde(rename = "FACULTY"))] | ||
Faculty, | ||
#[cfg_attr(feature = "serde_derive", serde(rename = "DEPARTMENT"))] | ||
Department, | ||
#[cfg_attr(feature = "serde_derive", serde(rename = "SPECIALTY"))] | ||
Specialty { terms: NodeTerms }, | ||
#[cfg_attr(feature = "serde_derive", serde(rename = "SECTOR"))] | ||
Sector { terms: NodeTerms }, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Clone)] | ||
#[cfg_attr(feature = "serde_derive", derive(Serialize, Deserialize))] | ||
#[cfg_attr( | ||
feature = "serde_derive", | ||
derive(Serialize, Deserialize), | ||
serde(rename_all = "camelCase") | ||
)] | ||
pub struct NodeTerms { | ||
pub per_year: usize, | ||
#[cfg(feature = "const")] | ||
#[cfg_attr(feature = "serde_derive", serde(skip_deserializing))] | ||
pub slots: &'static [i32], | ||
#[cfg(feature = "storage")] | ||
pub slots: Vec<i32>, | ||
} | ||
|
||
#[cfg(any(feature = "const", feature = "storage"))] | ||
#[derive(Debug, PartialEq)] | ||
#[cfg_attr(feature = "serde_derive", derive(Serialize, Deserialize))] | ||
pub struct Node { | ||
#[cfg(feature = "const")] | ||
#[cfg_attr(feature = "serde_derive", serde(borrow))] | ||
pub name: NodeName<'static>, | ||
#[cfg(feature = "storage")] | ||
pub name: NodeName, | ||
#[cfg_attr(feature = "serde_derive", serde(flatten))] | ||
pub r#type: NodeType, | ||
} |