Skip to content

Commit 274ae97

Browse files
committed
[feat] outsourcing Feature & ReaderError
1 parent 92af8c5 commit 274ae97

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

crates/package/src/lib.rs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1+
mod r#struct;
2+
mod r#enum;
3+
14
use serde::Deserialize;
25
use serde::de::DeserializeOwned;
36
use std::path::{Path, PathBuf};
47
use std::{fs, io};
58
use tucana::shared::{DefinitionDataType, FlowType, RuntimeFunctionDefinition, Version};
69
use walkdir::WalkDir;
7-
8-
#[derive(Deserialize, Debug, Clone)]
9-
pub struct Feature {
10-
pub name: String,
11-
pub data_types: Vec<DefinitionDataType>,
12-
pub flow_types: Vec<FlowType>,
13-
pub functions: Vec<RuntimeFunctionDefinition>,
14-
}
10+
use crate::r#enum::reader_error::ReaderError;
11+
use crate::r#struct::feature::Feature;
1512

1613
pub struct Reader {
1714
should_break: bool,
@@ -20,27 +17,21 @@ pub struct Reader {
2017
path: String,
2118
}
2219

23-
pub enum ReaderError {
24-
JsonError {
25-
path: PathBuf,
26-
error: serde_json::Error,
27-
},
28-
ReadFeatureError {
20+
impl Reader {
21+
pub fn configure(
2922
path: String,
30-
source: Box<ReaderError>,
31-
},
32-
ReadDirectoryError {
33-
path: PathBuf,
34-
error: io::Error,
35-
},
36-
ReadFileError {
37-
path: PathBuf,
38-
error: io::Error,
39-
},
40-
DirectoryEntryError(io::Error),
41-
}
23+
should_break: bool,
24+
accepted_features: Vec<String>,
25+
accepted_versions: Option<Version>,
26+
) -> Self {
27+
Self {
28+
should_break,
29+
accepted_features,
30+
accepted_versions,
31+
path,
32+
}
33+
}
4234

43-
impl Reader {
4435
pub fn read_features(&self, path: &str) -> Result<Vec<Feature>, ReaderError> {
4536
let definitions = Path::new(path);
4637

@@ -90,6 +81,13 @@ impl Reader {
9081
.to_string_lossy()
9182
.to_string();
9283

84+
if !self.accepted_features.is_empty()
85+
&& !self.accepted_features.contains(&feature_name)
86+
{
87+
log::info!("Skipping feature: {}", feature_name);
88+
continue;
89+
}
90+
9391
let data_types_path = path.join("data_type");
9492
let data_types: Vec<DefinitionDataType> =
9593
self.collect_definitions(&data_types_path)?;

0 commit comments

Comments
 (0)