Skip to content

Commit

Permalink
Merge pull request #55 from dzcode-io/feat/cargo-features-setup
Browse files Browse the repository at this point in the history
Add a `const` feature and updated Node model
  • Loading branch information
omdxp authored Jan 7, 2024
2 parents a4948a2 + fe804ff commit 8ffd8c1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name = "kuliya"
version = "0.1.0"
edition = "2021"

[features]
default = ["const"]
const = []

[dependencies]

[build-dependencies]
Expand Down
5 changes: 5 additions & 0 deletions rust/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#[cfg(feature = "const")]
use serde_json::Value;
#[cfg(feature = "const")]
use std::{fs, io, path::Path};

#[cfg(feature = "const")]
fn dir_tree_to_list(dir: impl AsRef<Path>) -> (String, String) {
let info_path = dir.as_ref().join("info.json");
let info_dot_json = match info_path.exists() {
Expand Down Expand Up @@ -104,6 +107,7 @@ fn dir_tree_to_list(dir: impl AsRef<Path>) -> (String, String) {
)
}

#[cfg(feature = "const")]
fn generate_data_file() -> Result<(), io::Error> {
let string_tree = dir_tree_to_list("../_data");

Expand Down Expand Up @@ -131,5 +135,6 @@ pub fn get_node_by_path(path: &str) -> Option<&Node> {{
}

fn main() {
#[cfg(feature = "const")]
generate_data_file().unwrap();
}
1 change: 1 addition & 0 deletions rust/src/api/get_node_by_path.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{_auto_generated, node::model::Node};

#[cfg(feature = "const")]
pub fn get_node_by_path(path: &str) -> Option<&Node> {
_auto_generated::data::get_node_by_path(path)
}
Expand Down
4 changes: 4 additions & 0 deletions rust/src/node/model.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#[derive(Debug, PartialEq)]
pub struct NodeName {
#[cfg(feature = "const")]
pub ar: &'static str,
#[cfg(feature = "const")]
pub en: &'static str,
#[cfg(feature = "const")]
pub fr: &'static str,
}

Expand All @@ -20,6 +23,7 @@ pub enum NodeType {
#[derive(Debug, PartialEq, Clone)]
pub struct NodeTerms {
pub per_year: usize,
#[cfg(feature = "const")]
pub slots: &'static [i32],
}

Expand Down

0 comments on commit 8ffd8c1

Please sign in to comment.