#[non_exhaustive]pub enum MetricsError {
EmptyRoot,
LanguageDisabled(LANG),
}Expand description
Error returned by the library’s metric-computation entry points.
§Stability
The variant set is additive: new variants may be introduced in
minor versions, so the enum is marked #[non_exhaustive]. Existing
variants will not be removed without a major version bump. The
std::error::Error and std::fmt::Display impls are part of
the stable surface; the exact wording of the Display output is
not.
§Examples
The MetricsError::EmptyRoot variant is reserved for a future
walker change (see its documentation). The
MetricsError::LanguageDisabled variant is the one actually
produced today: every dispatch entry point emits it when the
caller selects a
LANG whose per-language Cargo feature is not enabled in the
current build (see #252). The example exercises the happy path
and demonstrates the exhaustive-with-_ match shape that callers
should adopt to stay forward-compatible with future variants.
use big_code_analysis::{analyze, MetricsError, MetricsOptions, Source, LANG};
let source = Source::new(LANG::Cpp, b"int a = 42;");
let result = analyze(source, MetricsOptions::default());
// Today this call succeeds; the match below documents the shape
// callers must adopt so adding a future variant is non-breaking.
assert!(result.is_ok());
match result {
Ok(_space) => {}
Err(MetricsError::EmptyRoot) => {
// Reserved: walker produced no top-level FuncSpace.
}
Err(MetricsError::LanguageDisabled(_lang)) => {
// The `LANG` variant the caller asked for has no grammar
// crate compiled in for this build (per-language feature
// disabled — see the `[features]` table in Cargo.toml).
}
// `MetricsError` is `#[non_exhaustive]`; new variants may be added.
Err(_) => {}
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
EmptyRoot
The walker produced no top-level FuncSpace.
Reserved — not produced today. metrics_with_options always
pushes a synthetic top-level SpaceKind::Unit
FuncSpace onto its state stack before walking the AST, so
every parse — including empty input, whitespace-only input,
and comment-only input — currently returns
Ok(FuncSpace { kind: Unit, .. }). The variant is kept for a
future walker change that lets the state stack legitimately
drain to empty (e.g. an option that suppresses the synthetic
root for sources with no parseable structure).
LanguageDisabled(LANG)
The requested LANG is not enabled in this build.
Produced by every dispatch entry point
(crate::analyze, crate::Ast::parse,
crate::Ast::from_tree_sitter, and
crate::LANG::tree_sitter_language)
when the caller selects a LANG variant whose per-language
Cargo feature is not enabled in the current build — see the
[features] table in the root Cargo.toml for the list.
The default feature set (default = ["all-languages"]) keeps
every grammar compiled in, matching the library’s historical
behaviour; callers that opt into a narrower set with
--no-default-features --features rust,… are the only ones
that observe this variant.
Trait Implementations§
Source§impl Clone for MetricsError
impl Clone for MetricsError
Source§fn clone(&self) -> MetricsError
fn clone(&self) -> MetricsError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for MetricsError
Source§impl Debug for MetricsError
impl Debug for MetricsError
Source§impl Display for MetricsError
impl Display for MetricsError
impl Eq for MetricsError
Source§impl Error for MetricsError
impl Error for MetricsError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<MetricsError> for FromPathError
impl From<MetricsError> for FromPathError
Source§fn from(e: MetricsError) -> Self
fn from(e: MetricsError) -> Self
Source§impl PartialEq for MetricsError
impl PartialEq for MetricsError
Source§fn eq(&self, other: &MetricsError) -> bool
fn eq(&self, other: &MetricsError) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for MetricsError
Auto Trait Implementations§
impl Freeze for MetricsError
impl RefUnwindSafe for MetricsError
impl Send for MetricsError
impl Sync for MetricsError
impl Unpin for MetricsError
impl UnsafeUnpin for MetricsError
impl UnwindSafe for MetricsError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.