Skip to content

Commit 7d3128b

Browse files
committed
docs: update analysis method to use ast.analyze() and enhance result destructuring
1 parent c3f8db7 commit 7d3128b

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ assert!(roles.contains("admin"));
7070
### 2. Full analysis pass
7171

7272
When you need all fields at once — accessed variables, local variables, and
73-
string comparisons — call `analyze_ast` directly to avoid multiple traversals:
73+
string comparisons — call `ast.analyze()` (or the equivalent free function
74+
`analyze_ast(&ast)`). Destructuring the result moves each field out without
75+
any extra cloning:
7476

7577
```rust
7678
use rhai::Engine;
77-
use rhai_analyzer::analyze_ast;
79+
use rhai_analyzer::{RhaiAnalyzerExt, ScriptAnalysisResult};
7880

7981
let engine = Engine::new();
8082
let ast = engine.compile(r#"
@@ -84,16 +86,18 @@ let ast = engine.compile(r#"
8486
}
8587
"#).unwrap();
8688

87-
let result = analyze_ast(&ast);
89+
let ScriptAnalysisResult { accessed_variables, local_variables, string_comparisons } =
90+
ast.analyze();
8891

89-
assert!(result.accessed_variables.contains("request.amount"));
90-
assert!(result.local_variables.contains("status"));
91-
assert!(result.string_comparisons["user.role"].contains("admin"));
92+
assert!(accessed_variables.contains("request.amount"));
93+
assert!(local_variables.contains("status"));
94+
assert!(string_comparisons["user.role"].contains("admin"));
9295
```
9396

9497
### 3. Result data structure
9598

9699
```rust,ignore
100+
pub struct ScriptAnalysisResult {
97101
/// All unique, fully-qualified variable paths accessed in the script.
98102
pub accessed_variables: HashSet<String>,
99103

0 commit comments

Comments
 (0)