pub struct ComplexityMetrics {
pub cyclomatic_complexity: u32,
pub branches: u32,
pub loops: u32,
pub logical_operators: u32,
pub max_nesting_depth: u32,
pub exception_handlers: u32,
pub early_returns: u32,
}Expand description
Complexity metrics for a function or method.
These metrics help identify code that may be difficult to understand, test, or maintain.
Fields§
§cyclomatic_complexity: u32McCabe’s Cyclomatic Complexity (CC)
CC = 1 + number of decision points
- 1-5: Simple, low risk
- 6-10: Moderate complexity
- 11-20: Complex, moderate risk
- 21-50: Very complex, high risk
- 51+: Untestable, very high risk
branches: u32Number of branch statements (if, else if, else, switch/match cases)
loops: u32Number of loop constructs (for, while, loop, do-while)
logical_operators: u32Number of logical operators (&& / || / and / or)
max_nesting_depth: u32Maximum nesting depth of control structures
exception_handlers: u32Number of exception handlers (catch, except, rescue)
early_returns: u32Number of early returns (return statements not at the end)
Implementations§
Source§impl ComplexityMetrics
impl ComplexityMetrics
Sourcepub fn calculate_cyclomatic(&mut self)
pub fn calculate_cyclomatic(&mut self)
Calculate the cyclomatic complexity from the component counts
CC = 1 + branches + loops + logical_operators + exception_handlers
Sourcepub fn grade(&self) -> char
pub fn grade(&self) -> char
Get a letter grade based on cyclomatic complexity
- A: 1-5 (Simple, low risk)
- B: 6-10 (Moderate complexity)
- C: 11-20 (Complex, moderate risk)
- D: 21-50 (Very complex, high risk)
- F: 51+ (Untestable, very high risk)
Sourcepub fn exceeds_threshold(&self, threshold: u32) -> bool
pub fn exceeds_threshold(&self, threshold: u32) -> bool
Check if complexity exceeds a threshold
Sourcepub fn has_high_nesting(&self) -> bool
pub fn has_high_nesting(&self) -> bool
Check if the function has high nesting (> 4 levels)
Sourcepub fn merge_nested(&mut self, nested: &ComplexityMetrics)
pub fn merge_nested(&mut self, nested: &ComplexityMetrics)
Merge metrics from a nested scope (used when traversing nested functions)
pub fn with_branches(self, count: u32) -> Self
pub fn with_loops(self, count: u32) -> Self
pub fn with_logical_operators(self, count: u32) -> Self
pub fn with_nesting_depth(self, depth: u32) -> Self
pub fn with_exception_handlers(self, count: u32) -> Self
pub fn with_early_returns(self, count: u32) -> Self
Trait Implementations§
Source§impl Clone for ComplexityMetrics
impl Clone for ComplexityMetrics
Source§fn clone(&self) -> ComplexityMetrics
fn clone(&self) -> ComplexityMetrics
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ComplexityMetrics
impl Debug for ComplexityMetrics
Source§impl Default for ComplexityMetrics
impl Default for ComplexityMetrics
Source§fn default() -> ComplexityMetrics
fn default() -> ComplexityMetrics
Source§impl<'de> Deserialize<'de> for ComplexityMetrics
impl<'de> Deserialize<'de> for ComplexityMetrics
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ComplexityMetrics
impl PartialEq for ComplexityMetrics
Source§impl Serialize for ComplexityMetrics
impl Serialize for ComplexityMetrics
impl StructuralPartialEq for ComplexityMetrics
Auto Trait Implementations§
impl Freeze for ComplexityMetrics
impl RefUnwindSafe for ComplexityMetrics
impl Send for ComplexityMetrics
impl Sync for ComplexityMetrics
impl Unpin for ComplexityMetrics
impl UnwindSafe for ComplexityMetrics
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)