Struct arithmetic_typing::arith::NumArithmetic
source · pub struct NumArithmetic { /* private fields */ }
Expand description
Arithmetic on Num
bers.
§Unary ops
- Unary minus is follows the equation
-T == T
, whereT
is any linear type. - Unary negation is only defined for
Bool
s.
§Binary ops
Binary ops fall into 3 cases: Num op T == T
, T op Num == T
, or T op T == T
,
where T
is any linear type (that is, Num
or tuple of linear types).
T op T
is assumed by default, only falling into two other cases if one of operands
is known to be a number and the other is not a number.
§Comparisons
Order comparisons (>
, <
, >=
, <=
) can be switched on or off. Use
Self::with_comparisons()
constructor to switch them on. If switched on, both arguments
of the order comparison must be numbers.
Implementations§
source§impl NumArithmetic
impl NumArithmetic
sourcepub const fn without_comparisons() -> Self
pub const fn without_comparisons() -> Self
Creates an instance of arithmetic that does not support order comparisons.
sourcepub const fn with_comparisons() -> Self
pub const fn with_comparisons() -> Self
Creates an instance of arithmetic that supports order comparisons.
sourcepub fn unify_binary_op<Prim: PrimitiveType>(
substitutions: &mut Substitutions<Prim>,
context: &BinaryOpContext<Prim>,
errors: OpErrors<'_, Prim>,
settings: OpConstraintSettings<'_, Prim>,
) -> Type<Prim>
pub fn unify_binary_op<Prim: PrimitiveType>( substitutions: &mut Substitutions<Prim>, context: &BinaryOpContext<Prim>, errors: OpErrors<'_, Prim>, settings: OpConstraintSettings<'_, Prim>, ) -> Type<Prim>
Applies binary ops logic to unify the given LHS and RHS types. Returns the result type of the binary operation.
This logic can be reused by other TypeArithmetic
implementations.
§Arguments
settings
are applied to arguments of arithmetic ops.
sourcepub fn process_unary_op<Prim: WithBoolean>(
substitutions: &mut Substitutions<Prim>,
context: &UnaryOpContext<Prim>,
errors: OpErrors<'_, Prim>,
constraints: &impl Constraint<Prim>,
) -> Type<Prim>
pub fn process_unary_op<Prim: WithBoolean>( substitutions: &mut Substitutions<Prim>, context: &UnaryOpContext<Prim>, errors: OpErrors<'_, Prim>, constraints: &impl Constraint<Prim>, ) -> Type<Prim>
Processes a unary operation according to the numeric arithmetic rules. Returns the result type of the unary operation.
This logic can be reused by other TypeArithmetic
implementations.
sourcepub fn process_binary_op<Prim: WithBoolean>(
substitutions: &mut Substitutions<Prim>,
context: &BinaryOpContext<Prim>,
errors: OpErrors<'_, Prim>,
comparable_type: Option<Prim>,
settings: OpConstraintSettings<'_, Prim>,
) -> Type<Prim>
pub fn process_binary_op<Prim: WithBoolean>( substitutions: &mut Substitutions<Prim>, context: &BinaryOpContext<Prim>, errors: OpErrors<'_, Prim>, comparable_type: Option<Prim>, settings: OpConstraintSettings<'_, Prim>, ) -> Type<Prim>
Processes a binary operation according to the numeric arithmetic rules. Returns the result type of the unary operation.
This logic can be reused by other TypeArithmetic
implementations.
§Arguments
- If
comparable_type
is set toSome(_)
, it will be used to unify arguments of order comparisons. Ifcomparable_type
isNone
, order comparisons are not supported. constraints
are applied to arguments of arithmetic ops.
Trait Implementations§
source§impl Clone for NumArithmetic
impl Clone for NumArithmetic
source§fn clone(&self) -> NumArithmetic
fn clone(&self) -> NumArithmetic
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for NumArithmetic
impl Debug for NumArithmetic
source§impl<Val> MapPrimitiveType<Val> for NumArithmetic
impl<Val> MapPrimitiveType<Val> for NumArithmetic
source§impl TypeArithmetic<Num> for NumArithmetic
impl TypeArithmetic<Num> for NumArithmetic
source§fn process_unary_op(
&self,
substitutions: &mut Substitutions<Num>,
context: &UnaryOpContext<Num>,
errors: OpErrors<'_, Num>,
) -> Type<Num>
fn process_unary_op( &self, substitutions: &mut Substitutions<Num>, context: &UnaryOpContext<Num>, errors: OpErrors<'_, Num>, ) -> Type<Num>
source§fn process_binary_op(
&self,
substitutions: &mut Substitutions<Num>,
context: &BinaryOpContext<Num>,
errors: OpErrors<'_, Num>,
) -> Type<Num>
fn process_binary_op( &self, substitutions: &mut Substitutions<Num>, context: &BinaryOpContext<Num>, errors: OpErrors<'_, Num>, ) -> Type<Num>
Auto Trait Implementations§
impl Freeze for NumArithmetic
impl RefUnwindSafe for NumArithmetic
impl Send for NumArithmetic
impl Sync for NumArithmetic
impl Unpin for NumArithmetic
impl UnwindSafe for NumArithmetic
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)