Skip to main content

MetricsError

Enum MetricsError 

Source
#[non_exhaustive]
pub enum MetricsError { EmptyRoot, LanguageDisabled(LANG), NonUtf8Path, ParseHasErrors, }
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

Most variants are reserved for features that have not yet landed (see each variant’s documentation for the issue tracking it). The exception is MetricsError::LanguageDisabled, which is produced by every dispatch entry point 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::ParseHasErrors) => {
        // Reserved: future strict-parsing toggle on `MetricsOptions`.
    }
    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).
    }
    Err(MetricsError::NonUtf8Path) => {
        // Reserved: strict-identifier mode (see issue #254).
    }
    // `MetricsError` is `#[non_exhaustive]`; new variants may be added.
    Err(_) => {}
}

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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::metrics_from_tree, crate::action, crate::get_ops, the deprecated get_function_spaces* shims, and crate::LANG::get_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.

§

NonUtf8Path

The supplied path could not be losslessly converted to UTF-8.

Reserved for callers that opt into strict-identifier mode. As of #254, the recommended crate::analyze entry point accepts a crate::Source with an explicit Source::name: Option<String> so callers never need to round- trip a non-UTF-8 path through lossy conversion in the first place. The deprecated path-positional entry points (metrics, crate::get_function_spaces, …) still fall back to Path::to_string_lossy. This variant is not produced today; it is kept for future strict-identifier validators that reject lossy names up front.

§

ParseHasErrors

The tree-sitter parse tree contains syntax errors and the caller opted into strict mode.

Reserved for a future strict-parsing toggle on MetricsOptions; the current entry points still tolerate ERROR nodes and compute best-effort metrics, so this variant is not produced today.

Trait Implementations§

Source§

impl Clone for MetricsError

Source§

fn clone(&self) -> MetricsError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MetricsError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for MetricsError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for MetricsError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for MetricsError

Source§

fn eq(&self, other: &MetricsError) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for MetricsError

Source§

impl Eq for MetricsError

Source§

impl StructuralPartialEq for MetricsError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.