Skip to main content

MaybeMath

Trait MaybeMath 

Source
pub trait MaybeMath<In, Out> {
    // Required methods
    fn maybe_min(self, rhs: In) -> Out;
    fn maybe_max(self, rhs: In) -> Out;
    fn maybe_clamp(self, min: In, max: In) -> Out;
    fn maybe_add(self, rhs: In) -> Out;
    fn maybe_sub(self, rhs: In) -> Out;
}
Expand description

A trait to conveniently calculate minimums and maximums when some data may not be defined

If the left-hand value is None, these operations return None. If the right-hand value is None, it is treated as zero.

Required Methods§

Source

fn maybe_min(self, rhs: In) -> Out

Returns the minimum of self and rhs

Source

fn maybe_max(self, rhs: In) -> Out

Returns the maximum of self and rhs

Source

fn maybe_clamp(self, min: In, max: In) -> Out

Returns self clamped between min and max

Source

fn maybe_add(self, rhs: In) -> Out

Adds self and rhs.

Source

fn maybe_sub(self, rhs: In) -> Out

Subtracts rhs from self, treating None values as default

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl MaybeMath<Option<f32>, Option<f32>> for Option<f32>

Source§

fn maybe_min(self, rhs: Option<f32>) -> Option<f32>

Source§

fn maybe_max(self, rhs: Option<f32>) -> Option<f32>

Source§

fn maybe_clamp(self, min: Option<f32>, max: Option<f32>) -> Option<f32>

Source§

fn maybe_add(self, rhs: Option<f32>) -> Option<f32>

Source§

fn maybe_sub(self, rhs: Option<f32>) -> Option<f32>

Source§

impl MaybeMath<Option<f32>, f32> for f32

Source§

fn maybe_min(self, rhs: Option<f32>) -> f32

Source§

fn maybe_max(self, rhs: Option<f32>) -> f32

Source§

fn maybe_clamp(self, min: Option<f32>, max: Option<f32>) -> f32

Source§

fn maybe_add(self, rhs: Option<f32>) -> f32

Source§

fn maybe_sub(self, rhs: Option<f32>) -> f32

Source§

impl MaybeMath<f32, Option<f32>> for Option<f32>

Source§

fn maybe_min(self, rhs: f32) -> Option<f32>

Source§

fn maybe_max(self, rhs: f32) -> Option<f32>

Source§

fn maybe_clamp(self, min: f32, max: f32) -> Option<f32>

Source§

fn maybe_add(self, rhs: f32) -> Option<f32>

Source§

fn maybe_sub(self, rhs: f32) -> Option<f32>

Implementors§