pub struct Confidence(/* private fields */);Expand description
A memory’s confidence as a 0-100 percentage.
A newtype over i8 whose only constructor clamps into [0, 100], so an
out-of-range value is unrepresentable. This is the single home for the
scale-and-clamp logic: the extraction LLM emits an f32 (occasionally
> 1.0), which Confidence::from_unit_scale scales by 100 and clamps.
§Examples
use memoir_core::memory::Confidence;
assert_eq!(Confidence::new(73).get(), 73);
assert_eq!(Confidence::new(120).get(), 100); // clamped
assert_eq!(Confidence::from_unit_scale(0.42).get(), 42);
assert_eq!(Confidence::from_unit_scale(1.7).get(), 100); // clampedImplementations§
Source§impl Confidence
impl Confidence
Sourcepub const MAX: Confidence
pub const MAX: Confidence
Largest valid confidence: fully certain.
Sourcepub const MIN: Confidence
pub const MIN: Confidence
Smallest valid confidence: no certainty.
Sourcepub fn new(percent: i8) -> Self
pub fn new(percent: i8) -> Self
Creates a confidence from a percentage, clamping into [0, 100].
Clamping is the defined behavior, not an error: callers (and the extraction LLM) occasionally produce out-of-range values, and the intent is always “as confident as possible / not at all,” never a failure. Hence this is infallible.
Sourcepub fn from_unit_scale(score: f32) -> Self
pub fn from_unit_scale(score: f32) -> Self
Creates a confidence from a unit-scale score, scaling ×100 and clamping.
The extraction LLM emits a per-fact score in [0.0, 1.0] (but may
exceed 1.0). This scales to a percentage and clamps into [0, 100].
NaN maps to Confidence::MIN.
Trait Implementations§
Source§impl Clone for Confidence
impl Clone for Confidence
Source§fn clone(&self) -> Confidence
fn clone(&self) -> Confidence
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for Confidence
Source§impl Debug for Confidence
impl Debug for Confidence
Source§impl Default for Confidence
impl Default for Confidence
Source§impl Display for Confidence
impl Display for Confidence
impl Eq for Confidence
Source§impl Hash for Confidence
impl Hash for Confidence
Source§impl Ord for Confidence
impl Ord for Confidence
Source§fn cmp(&self, other: &Confidence) -> Ordering
fn cmp(&self, other: &Confidence) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for Confidence
impl PartialEq for Confidence
Source§fn eq(&self, other: &Confidence) -> bool
fn eq(&self, other: &Confidence) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for Confidence
impl PartialOrd 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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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> 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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§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<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().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.