Skip to content

Commit 32d4d68

Browse files
authored
Merge pull request #157 from code0-tech/136-update-readme-definition-reader
Update Readme Definition Reader
2 parents c7c8bf9 + a4a2612 commit 32d4d68

File tree

1 file changed

+65
-17
lines changed

1 file changed

+65
-17
lines changed

README.md

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,74 @@ Crate: [code0-definition-reader](https://crates.io/crates/code0-definition-reade
9898
cargo add code0-definition-reader
9999
```
100100

101-
### Usage
101+
### Basic Usage
102+
103+
```rs
104+
use code0_definition_reader::Reader;
105+
106+
fn main() {
107+
// Create a reader with default configuration
108+
let reader = Reader::configure(
109+
"./path/to/definitions".to_string(), // Path to definitions directory
110+
false, // should_break: continue on errors
111+
Vec::new(), // accepted_features: empty = all features
112+
None // accepted_version: None = all versions
113+
);
114+
115+
// Read all features
116+
match reader.read_features() {
117+
Ok(features) => {
118+
for feature in features {
119+
println!("Loaded feature: {}", feature.name);
120+
println!(" - Data Types: {}", feature.data_types.len());
121+
println!(" - Flow Types: {}", feature.flow_types.len());
122+
println!(" - Functions: {}", feature.functions.len());
123+
}
124+
}
125+
Err(err) => {
126+
eprintln!("Failed to read features: {:?}", err);
127+
}
128+
}
129+
}
130+
```
131+
132+
### Advanced Usage - Filter Specific Features
102133

103134
```rs
104135
use code0_definition_reader::Reader;
105136

106-
let reader = Reader::configure(
107-
String::new(), // Path required for configure
108-
false, // should_break
109-
Vec::new(), // accepted_features
110-
None // accepted_versions
111-
);
112-
113-
let features = reader.read_features("./path/to/definitions");
114-
115-
for feature in features {
116-
let name = &feature.name; // name of the feature (e.g., http)
117-
let data_types = &feature.data_types; // dataTypes of this feature
118-
let flow_types = &feature.flow_types; // flowTypes of this feature
119-
let functions = &feature.functions; // runtimeFunctions of this feature
120-
121-
println!("Loaded feature: {}", name);
137+
fn main() {
138+
let reader = Reader::configure(
139+
"./definitions".to_string(),
140+
false,
141+
vec!["http".to_string(), "database".to_string()], // Only load http and database features
142+
None
143+
);
144+
145+
match reader.read_features() {
146+
Ok(features) => {
147+
for feature in features {
148+
println!("Feature: {}", feature.name);
149+
150+
// Access data types
151+
for data_type in &feature.data_types {
152+
println!(" DataType: {}", data_type.identifier);
153+
}
154+
155+
// Access flow types
156+
for flow_type in &feature.flow_types {
157+
println!(" FlowType: {}", flow_type.identifier);
158+
}
159+
160+
// Access runtime functions
161+
for function in &feature.functions {
162+
println!(" Function: {}", function.runtime_name);
163+
}
164+
}
165+
}
166+
Err(err) => {
167+
eprintln!("Failed to read features: {:?}", err);
168+
}
169+
}
122170
}
123171
```

0 commit comments

Comments
 (0)