pub struct CoercionResult<T> {
pub value: T,
pub flags: Vec<CoercionFlag>,
pub confidence: f32,
}Expand description
Result of a coercion operation with transparency.
Tracks the value, all coercions applied, and confidence score.
Fields§
§value: TThe coerced value
flags: Vec<CoercionFlag>All coercion flags applied
confidence: f32Confidence score (0.0-1.0)
Implementations§
Source§impl<T> CoercionResult<T>
impl<T> CoercionResult<T>
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Create a new coercion result with perfect confidence.
§Example
use simple_agent_type::coercion::CoercionResult;
let result = CoercionResult::new(42);
assert_eq!(result.value, 42);
assert_eq!(result.confidence, 1.0);
assert!(result.flags.is_empty());Sourcepub fn with_confidence(value: T, confidence: f32) -> Self
pub fn with_confidence(value: T, confidence: f32) -> Self
Create a result with a specific confidence.
Sourcepub fn set_confidence(self, confidence: f32) -> Self
pub fn set_confidence(self, confidence: f32) -> Self
Set the confidence score (builder pattern).
Sourcepub fn with_flag(self, flag: CoercionFlag) -> Self
pub fn with_flag(self, flag: CoercionFlag) -> Self
Add a coercion flag.
Sourcepub fn with_flags(self, flags: Vec<CoercionFlag>) -> Self
pub fn with_flags(self, flags: Vec<CoercionFlag>) -> Self
Add multiple coercion flags.
Sourcepub fn was_coerced(&self) -> bool
pub fn was_coerced(&self) -> bool
Check if any coercions were applied.
§Example
use simple_agent_type::coercion::{CoercionResult, CoercionFlag};
let result = CoercionResult::new(42);
assert!(!result.was_coerced());
let result = result.with_flag(CoercionFlag::StrippedMarkdown);
assert!(result.was_coerced());Sourcepub fn is_confident(&self, threshold: f32) -> bool
pub fn is_confident(&self, threshold: f32) -> bool
Check if confidence meets a threshold.
§Example
use simple_agent_type::coercion::CoercionResult;
let result = CoercionResult::with_confidence(42, 0.8);
assert!(result.is_confident(0.7));
assert!(!result.is_confident(0.9));Sourcepub fn has_major_coercions(&self) -> bool
pub fn has_major_coercions(&self) -> bool
Check if any major coercions were applied.
Sourcepub fn map<U, F>(self, f: F) -> CoercionResult<U>where
F: FnOnce(T) -> U,
pub fn map<U, F>(self, f: F) -> CoercionResult<U>where
F: FnOnce(T) -> U,
Map the value while preserving flags and confidence.
Trait Implementations§
Source§impl<T: Clone> Clone for CoercionResult<T>
impl<T: Clone> Clone for CoercionResult<T>
Source§fn clone(&self) -> CoercionResult<T>
fn clone(&self) -> CoercionResult<T>
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<T: Debug> Debug for CoercionResult<T>
impl<T: Debug> Debug for CoercionResult<T>
Source§impl<'de, T> Deserialize<'de> for CoercionResult<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for CoercionResult<T>where
T: Deserialize<'de>,
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<T: PartialEq> PartialEq for CoercionResult<T>
impl<T: PartialEq> PartialEq for CoercionResult<T>
Source§impl<T> Serialize for CoercionResult<T>where
T: Serialize,
impl<T> Serialize for CoercionResult<T>where
T: Serialize,
impl<T> StructuralPartialEq for CoercionResult<T>
Auto Trait Implementations§
impl<T> Freeze for CoercionResult<T>where
T: Freeze,
impl<T> RefUnwindSafe for CoercionResult<T>where
T: RefUnwindSafe,
impl<T> Send for CoercionResult<T>where
T: Send,
impl<T> Sync for CoercionResult<T>where
T: Sync,
impl<T> Unpin for CoercionResult<T>where
T: Unpin,
impl<T> UnwindSafe for CoercionResult<T>where
T: UnwindSafe,
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