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 fn new(value: f64) -> Option<Self>
pub fn new(value: f64) -> Option<Self>
Create a confidence score, returning None if out of range.
Use this when invalid values should be handled explicitly.
Sourcepub fn saturating(value: f64) -> Self
pub fn saturating(value: f64) -> Self
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<Self>
pub fn from_percent(percent: f64) -> Option<Self>
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).
Trait Implementations§
Source§impl Clone for Confidence
impl Clone for Confidence
Source§fn clone(&self) -> Confidence
fn clone(&self) -> Confidence
Returns a duplicate of the value. Read more
1.0.0 · 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 Confidence
impl Debug for Confidence
Source§impl Default for Confidence
impl Default for Confidence
Source§impl<'de> Deserialize<'de> for Confidence
impl<'de> Deserialize<'de> for Confidence
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for Confidence
impl Display for Confidence
Source§impl From<Confidence> for f64
impl From<Confidence> for f64
Source§fn from(conf: Confidence) -> Self
fn from(conf: Confidence) -> Self
Converts to this type from the input type.
Source§impl From<Score> for Confidence
impl From<Score> for 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§impl TryFrom<f64> for Confidence
impl TryFrom<f64> for Confidence
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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>
Fallible version of
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a
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.