Skip to main content

ImpactScore

Struct ImpactScore 

Source
pub struct ImpactScore(/* private fields */);
Expand description

Validated impact score representing error severity (0-1000).

§Purpose

This newtype centralizes impact validation and makes the type system encode security policy:

  • Impact scores must be in valid range (0-1000)
  • Construction enforces validation once at creation
  • Downstream consumers receive pre-validated scores

§Copy Semantics

This type is Copy because:

  • It’s a small numeric value (u16)
  • No governance risk from duplication
  • Defensive code benefits from pass-by-value semantics

§Feature: Strict Severity Authority

When strict_severity feature is enabled, additional constraints apply based on namespace authority flags. See ErrorNamespace::CAN_BREACH.

§Example

// Compile-time validation
const MINOR_IMPACT: ImpactScore = ImpactScore::new(150);

// Runtime validation
let score = ImpactScore::checked_new(user_input).unwrap();

Implementations§

Source§

impl ImpactScore

Source

pub const fn new(score: u16) -> Self

Create a new impact score with compile-time validation.

§Panics

Panics at compile time (in const contexts) if score > 1000. Panics at runtime (in non-const contexts) if score > 1000.

§Use Case

For const static error code definitions where scores are known at compile time.

Source

pub fn checked_new(score: u16) -> Result<Self, ImpactScoreError>

Create a new impact score with runtime validation.

§Errors

Returns Err if score > 1000.

§Use Case

For runtime paths where impact scores come from configuration, user input, or dynamic sources. Prevents panics.

Source

pub const fn value(self) -> u16

Get the raw numeric value.

Source

pub const fn to_impact_level(self) -> ErrorImpact

Convert to detailed impact level classification.

Source

pub const fn is_breach_level(self) -> bool

Check if this is a Breach-level impact (951-1000).

Trait Implementations§

Source§

impl Clone for ImpactScore

Source§

fn clone(&self) -> ImpactScore

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ImpactScore

Source§

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

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

impl Display for ImpactScore

Source§

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

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

impl Hash for ImpactScore

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ImpactScore

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 ImpactScore

Source§

impl Eq for ImpactScore

Source§

impl StructuralPartialEq for ImpactScore

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<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> 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.