Skip to main content

CoercionResult

Struct CoercionResult 

Source
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: T

The coerced value

§flags: Vec<CoercionFlag>

All coercion flags applied

§confidence: f32

Confidence score (0.0-1.0)

Implementations§

Source§

impl<T> CoercionResult<T>

Source

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());
Source

pub fn with_confidence(value: T, confidence: f32) -> Self

Create a result with a specific confidence.

Source

pub fn set_confidence(self, confidence: f32) -> Self

Set the confidence score (builder pattern).

Source

pub fn with_flag(self, flag: CoercionFlag) -> Self

Add a coercion flag.

Source

pub fn with_flags(self, flags: Vec<CoercionFlag>) -> Self

Add multiple coercion flags.

Source

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());
Source

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));
Source

pub fn has_major_coercions(&self) -> bool

Check if any major coercions were applied.

Source

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>

Source§

fn clone(&self) -> CoercionResult<T>

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<T: Debug> Debug for CoercionResult<T>

Source§

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

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

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

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: PartialEq> PartialEq for CoercionResult<T>

Source§

fn eq(&self, other: &CoercionResult<T>) -> 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<T> Serialize for CoercionResult<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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> 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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,