Using as a Library
big-code-analysis is published on crates.io as a Rust library. The
CLI (bca) and REST server (bca-web) are both thin wrappers around
the same public API, so anything they can do you can do directly from
your own crate.
This section is task-oriented. For full type signatures and field docs, follow the rustdoc on docs.rs.
When to embed the library
Use the library instead of shelling out to bca when you want any
of the following:
- In-process analysis. Avoid spawning a subprocess per file when scoring thousands of files in a custom tool, IDE plugin, or static-analysis pipeline.
- In-memory source. Score generated, pre-processed, or streamed source without writing it to disk first. See Analyzing in-memory source.
- Selective walking. Drive a custom traversal over the
FuncSpacetree to extract per-function metrics on your own schedule. See Walking FuncSpace results. - Custom output. Skip the
bcaserializers (JSON / YAML / TOML / CBOR in the CLI, CSV / SARIF / Checkstyle in the library’soutputmodule) and emit your own format, such as a database row.
If you only want a Markdown quality report or a CI threshold gate,
the bca CLI is faster to wire up.
Pages in this section
- Quick start: parse a string, get a
FuncSpace, print the cognitive complexity. - Analyzing in-memory source: feed source from a buffer rather than a file.
- Reusing an existing tree-sitter Tree: feed a
caller-built
tree_sitter::Treeinto the metric walker. - Parse once, run metrics many times: hold a parsed
Astand run several metric subsets or custom walks against the same tree. - Walking the AST directly: count syntactic constructs, find nodes by kind, detect parse errors, or build a symbol table alongside the metrics walk.
- Selecting metrics: compute only the metrics
you need with
MetricsOptions::with_only, including how dependent metrics pull in their inputs. - Walking
FuncSpaceresults: recurse into nested function, class and impl spaces. - Error handling: interpret
Result<FuncSpace, MetricsError>and turn errors into useful diagnostics. - Stability and versioning: identify what stays
stable across the
2.xline.
API stability
The library is on the 2.x line and ships under a written
stability contract: the shape of the public API is
held stable across patch and minor bumps, and breaking changes are
reserved for the next major bump. Every example in this section
compiles against the current published crate and is expected to keep
compiling across 2.x without edits.
Metric values may still drift across minor bumps when a grammar pin moves or a metric definition is fixed; see STABILITY.md § What is stable in value for the carve-out. Each drift is called out in the changelog entry that introduces it.