pub struct RefinementType {
pub base_type: String,
pub name: Option<String>,
pub predicates: Vec<RefinementPredicate>,
pub description: Option<String>,
}Expand description
A refinement type combining a base type with predicates.
Fields§
§base_type: StringBase type name
name: Option<String>Optional refined name (e.g., “PositiveInt” for Int{x > 0})
predicates: Vec<RefinementPredicate>Predicates that constrain values
description: Option<String>Description of the refinement
Implementations§
Source§impl RefinementType
impl RefinementType
Sourcepub fn new(base_type: impl Into<String>) -> Self
pub fn new(base_type: impl Into<String>) -> Self
Create a new refinement type with a base type.
Sourcepub fn with_predicate(self, predicate: RefinementPredicate) -> Self
pub fn with_predicate(self, predicate: RefinementPredicate) -> Self
Add a predicate to the refinement.
Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
Set the description.
Sourcepub fn check_with_context(
&self,
value: f64,
context: &RefinementContext,
) -> bool
pub fn check_with_context( &self, value: f64, context: &RefinementContext, ) -> bool
Check if a value satisfies this refinement type with context.
Sourcepub fn is_subtype_of(&self, other: &RefinementType) -> bool
pub fn is_subtype_of(&self, other: &RefinementType) -> bool
Check if this is a subtype of another refinement type.
A refinement type A is a subtype of B if:
- They have the same base type
- A’s predicates imply B’s predicates
This implementation uses semantic implication checking for common predicate patterns, providing a practical alternative to full SMT solving while handling most real-world cases.
Sourcepub fn free_variables(&self) -> Vec<String>
pub fn free_variables(&self) -> Vec<String>
Get all free variables referenced in predicates.
Sourcepub fn to_string_repr(&self) -> String
pub fn to_string_repr(&self) -> String
Convert to human-readable representation.
Trait Implementations§
Source§impl Clone for RefinementType
impl Clone for RefinementType
Source§fn clone(&self) -> RefinementType
fn clone(&self) -> RefinementType
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 moreAuto Trait Implementations§
impl Freeze for RefinementType
impl !RefUnwindSafe for RefinementType
impl Send for RefinementType
impl Sync for RefinementType
impl Unpin for RefinementType
impl !UnwindSafe for RefinementType
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