pub struct Confidence(/* private fields */);Expand description
A confidence score guaranteed to be in the range [0.0, 1.0].
This is a “witness type” - its existence proves the value is valid.
Once you have a Confidence, you never need to check bounds again.
§Construction
Confidence::new: ReturnsNoneif out of range (strict parsing)Confidence::saturating: Clamps to [0, 1] (lenient, never fails)Confidence::try_from: ReturnsErrif out of range
§Zero-Cost Abstraction
Confidence is #[repr(transparent)], meaning it has the exact same
memory layout as f64. There is no runtime overhead.
§Example
use anno::types::Confidence;
// Strict: fail on invalid input
assert!(Confidence::new(0.5).is_some());
assert!(Confidence::new(1.5).is_none());
// Lenient: clamp to valid range
let conf = Confidence::saturating(1.5);
assert_eq!(conf.get(), 1.0);
// Use with Entity - convert to f64 with .get()
use anno::{Entity, EntityType};
let entity = Entity::new("test", EntityType::Person, 0, 4, conf.get());Implementations§
Source§impl Confidence
impl Confidence
Sourcepub const MIN: Confidence
pub const MIN: Confidence
The minimum valid confidence value.
Sourcepub const MAX: Confidence
pub const MAX: Confidence
The maximum valid confidence value.
Sourcepub const CERTAIN: Confidence
pub const CERTAIN: Confidence
A “perfect” confidence of 1.0 (deterministic/regex-based extraction).
Sourcepub const UNCERTAIN: Confidence
pub const UNCERTAIN: Confidence
A “no information” confidence of 0.5 (maximum entropy).
Sourcepub fn new(value: f64) -> Option<Confidence>
pub fn new(value: f64) -> Option<Confidence>
Create a confidence score, returning None if out of range.
Use this when invalid values should be handled explicitly.
Sourcepub fn saturating(value: f64) -> Confidence
pub fn saturating(value: f64) -> Confidence
Create a confidence score, clamping to [0.0, 1.0].
Use this when you want lenient handling of out-of-range values. NaN is treated as 0.0.
Sourcepub fn from_percent(percent: f64) -> Option<Confidence>
pub fn from_percent(percent: f64) -> Option<Confidence>
Create a confidence score from a percentage (0-100).
Sourcepub fn as_percent(self) -> f64
pub fn as_percent(self) -> f64
Convert to percentage (0-100).
Sourcepub fn lerp(self, other: Confidence, t: f64) -> Confidence
pub fn lerp(self, other: Confidence, t: f64) -> Confidence
Linear interpolation between two confidence values.
t = 0.0 returns self, t = 1.0 returns other.
Sourcepub fn combine(self, other: Confidence) -> Confidence
pub fn combine(self, other: Confidence) -> Confidence
Combine two confidence scores (geometric mean).
Geometric mean penalizes low scores more than arithmetic mean, which is appropriate for independent confidence estimates.
Trait Implementations§
Source§impl Clone for Confidence
impl Clone for Confidence
Source§fn clone(&self) -> Confidence
fn clone(&self) -> Confidence
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Confidence
impl Debug for Confidence
Source§impl Default for Confidence
impl Default for Confidence
Source§fn default() -> Confidence
fn default() -> Confidence
Source§impl<'de> Deserialize<'de> for Confidence
impl<'de> Deserialize<'de> for Confidence
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Confidence, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Confidence, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for Confidence
impl Display for Confidence
Source§impl From<Score> for Confidence
impl From<Score> for Confidence
Source§fn from(score: Score) -> Confidence
fn from(score: Score) -> Confidence
Source§impl PartialEq<f64> for Confidence
impl PartialEq<f64> for Confidence
Source§impl PartialEq for Confidence
impl PartialEq for Confidence
Source§impl PartialOrd<f64> for Confidence
impl PartialOrd<f64> for Confidence
Source§impl PartialOrd for Confidence
impl PartialOrd for Confidence
Source§impl Serialize for Confidence
impl Serialize for Confidence
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl TryFrom<f64> for Confidence
impl TryFrom<f64> for Confidence
Source§type Error = ConfidenceError
type Error = ConfidenceError
Source§fn try_from(
value: f64,
) -> Result<Confidence, <Confidence as TryFrom<f64>>::Error>
fn try_from( value: f64, ) -> Result<Confidence, <Confidence as TryFrom<f64>>::Error>
impl Copy for Confidence
impl StructuralPartialEq for Confidence
Auto Trait Implementations§
impl Freeze for Confidence
impl RefUnwindSafe for Confidence
impl Send for Confidence
impl Sync for Confidence
impl Unpin for Confidence
impl UnsafeUnpin for Confidence
impl UnwindSafe for Confidence
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<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read moreSource§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.