11---
22title : Rust API
3- description : Rust bounded parsing, diagnostics, canonical digests, native ACL generation, AST, and builders for a3s-acl.
3+ description : Rust bounded parsing, multi- diagnostics, canonical digests, native ACL generation, AST, and builders for a3s-acl.
44---
55
66# Rust API
@@ -34,8 +34,9 @@ The public crate exports:
3434| API | Role |
3535| --- | --- |
3636| ` parse ` / ` parse_acl ` | Parse ACL text into a ` Document ` . |
37- | ` parse_with_limits ` , ` ParseLimits ` | Parse untrusted input with explicit document, nesting, collection, and token limits. |
38- | ` DiagnosticCode ` , ` ParseError ` | Return stable codes, UTF-8 byte spans, and redacted messages. |
37+ | ` parse_with_limits ` , ` ParseLimits ` | Parse untrusted input with explicit document, nesting, collection, token, and diagnostic limits. |
38+ | ` collect_diagnostics ` , ` collect_diagnostics_with_limits ` | Collect bounded diagnostics without constructing a partial AST. |
39+ | ` DiagnosticCode ` , ` ParseError ` , ` DiagnosticReport ` | Return stable codes, UTF-8 byte spans, redacted messages, and explicit truncation state. |
3940| ` generate ` / ` generate_acl ` | Generate ACL text from a ` Document ` . |
4041| ` generate_from_map ` | Build ACL text from a ` HashMap<String, Value> ` . |
4142| ` canonical_bytes ` , ` canonical_digest ` | Produce stable cross-SDK bytes and an algorithm-prefixed SHA-256 digest. |
@@ -55,6 +56,7 @@ let document = parse_with_limits(
5556 max_nesting_depth : 32 ,
5657 max_collection_items : 1_000 ,
5758 max_token_bytes : 16 * 1024 ,
59+ max_diagnostics : 20 ,
5860 },
5961)? ;
6062```
@@ -64,6 +66,26 @@ Document and token sizes count UTF-8 bytes. `ParseError` exposes a stable
6466compatibility ` line ` / ` column ` fields. Messages identify token kinds without
6567including source token values or snippets.
6668
69+ The parse APIs remain fail-fast. CLI and editor integrations can collect
70+ multiple errors with a bounded budget:
71+
72+ ``` rust
73+ use a3s_acl :: {collect_diagnostics_with_limits, ParseLimits };
74+
75+ let report = collect_diagnostics_with_limits (
76+ " first = ]\ n second = ]" ,
77+ ParseLimits {
78+ max_diagnostics : 20 ,
79+ .. ParseLimits :: default ()
80+ },
81+ );
82+ ```
83+
84+ After a syntax error, collection resumes at the next source line.
85+ Resource-limit diagnostics remain fatal. A report stores at most
86+ ` max_diagnostics ` errors and sets ` truncated ` only after observing another
87+ error beyond that budget.
88+
6789## AST
6890
6991| Type | Fields |
0 commit comments