pub struct MethodMetrics { /* private fields */ }Expand description
Metrics collected for a single method in a type.
The lint driver populates this struct from HIR analysis. The CC value is the SonarSource-style cognitive complexity count; LOC is the span line count. Both values are pre-computed by the caller.
§Examples
use whitaker_common::brain_type_metrics::MethodMetrics;
let m = MethodMetrics::new("parse", 31, 140);
assert_eq!(m.name(), "parse");
assert_eq!(m.cognitive_complexity(), 31);
assert_eq!(m.lines_of_code(), 140);Implementations§
Source§impl MethodMetrics
impl MethodMetrics
Sourcepub fn new(
name: impl Into<String>,
cognitive_complexity: usize,
lines_of_code: usize,
) -> Self
pub fn new( name: impl Into<String>, cognitive_complexity: usize, lines_of_code: usize, ) -> Self
Creates a new per-method metrics record.
§Examples
use whitaker_common::brain_type_metrics::MethodMetrics;
let m = MethodMetrics::new("validate", 10, 45);
assert_eq!(m.name(), "validate");Sourcepub fn cognitive_complexity(&self) -> usize
pub fn cognitive_complexity(&self) -> usize
Returns the cognitive complexity (CC) value.
Sourcepub fn lines_of_code(&self) -> usize
pub fn lines_of_code(&self) -> usize
Returns the lines of code (LOC) count.
Sourcepub fn is_brain_method(&self, cc_threshold: usize, loc_threshold: usize) -> bool
pub fn is_brain_method(&self, cc_threshold: usize, loc_threshold: usize) -> bool
Returns true when this method qualifies as a “brain method”.
A brain method has cognitive complexity >= cc_threshold and
lines of code >= loc_threshold. Both conditions must hold.
§Examples
use whitaker_common::brain_type_metrics::MethodMetrics;
let m = MethodMetrics::new("parse", 30, 100);
assert!(m.is_brain_method(25, 80));
assert!(!m.is_brain_method(25, 200));Trait Implementations§
Source§impl Clone for MethodMetrics
impl Clone for MethodMetrics
Source§fn clone(&self) -> MethodMetrics
fn clone(&self) -> MethodMetrics
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MethodMetrics
impl Debug for MethodMetrics
impl Eq for MethodMetrics
Source§impl PartialEq for MethodMetrics
impl PartialEq for MethodMetrics
impl StructuralPartialEq for MethodMetrics
Auto Trait Implementations§
impl Freeze for MethodMetrics
impl RefUnwindSafe for MethodMetrics
impl Send for MethodMetrics
impl Sync for MethodMetrics
impl Unpin for MethodMetrics
impl UnsafeUnpin for MethodMetrics
impl UnwindSafe for MethodMetrics
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
Mutably borrows from an owned value. Read more