Skip to main content

SpinValue

Trait SpinValue 

Source
pub trait SpinValue:
    Sealed
    + Copy
    + PartialOrd
    + Debug
    + 'static {
    // Required methods
    fn to_f64(self) -> f64;
    fn from_f64_saturating(v: f64) -> Self;
    fn parse(s: &str) -> Option<Self>;
    fn format(self, decimals: u8) -> String;
    fn saturating_add(self, rhs: Self) -> Self;
    fn saturating_sub(self, rhs: Self) -> Self;
    fn saturating_mul_u32(self, rhs: u32) -> Self;
    fn is_integer() -> bool;
    fn is_valid_input_char(c: char) -> bool;

    // Provided method
    fn clamp_value(self, min: Self, max: Self) -> Self { ... }
}
Expand description

Numeric primitive that a SpinBox can hold.

Sealed: only the primitive integer and floating-point types implement this. See the module docs for the rationale.

Implementations must provide lossless parsing and round-trip formatting (parse(format(v, d)) == Some(v) for any finite value v and decimals d). Arithmetic is saturating so clamping into [min, max] after a step cannot overflow.

Required Methods§

Source

fn to_f64(self) -> f64

Lossless widening to f64. Used for AccessKit’s numeric value / min / max / step properties and for StepType::Adaptive decimal analysis.

Source

fn from_f64_saturating(v: f64) -> Self

Narrowing from f64 with saturation at the type’s full range. For integers the conversion truncates toward zero, matching Rust’s as conversion semantics.

Source

fn parse(s: &str) -> Option<Self>

Parse a user-entered string. Leading/trailing whitespace is ignored. Returns None for syntactically invalid input (but NOT for out-of-range values — the SpinBox clamps separately so users can type past the bound and see the reformatted clamped result after blur).

Source

fn format(self, decimals: u8) -> String

Format for display.

For integer types, decimals is ignored. For floats, the value is rendered with exactly decimals digits after the decimal point — no scientific notation, no thousands separator. Formatter closures on SpinBox (text_from_value) override this.

Source

fn saturating_add(self, rhs: Self) -> Self

Saturating addition. Out-of-type-range results clamp at MAX (or MIN for negative overflow on signed types).

Source

fn saturating_sub(self, rhs: Self) -> Self

Saturating subtraction. See saturating_add.

Source

fn saturating_mul_u32(self, rhs: u32) -> Self

Saturating multiplication by a positive integer. Used for page_step = multiplier × single_step when the caller omits a page step.

Source

fn is_integer() -> bool

Whether this type has integer semantics (no fractional component, no decimal separator in the default format path). Controls the default character filter and whether decimals has any effect.

Source

fn is_valid_input_char(c: char) -> bool

Default per-character input filter for the editable field. Admits digits and, for signed types, -; float types also admit ., +, e, E. Callers can override the whole filter on the SpinBox builder.

Provided Methods§

Source

fn clamp_value(self, min: Self, max: Self) -> Self

Clamp into an inclusive range. Falls through to PartialOrd.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl SpinValue for f32

Source§

fn to_f64(self) -> f64

Source§

fn from_f64_saturating(v: f64) -> Self

Source§

fn parse(s: &str) -> Option<Self>

Source§

fn format(self, decimals: u8) -> String

Source§

fn saturating_add(self, rhs: Self) -> Self

Source§

fn saturating_sub(self, rhs: Self) -> Self

Source§

fn saturating_mul_u32(self, rhs: u32) -> Self

Source§

fn is_integer() -> bool

Source§

fn is_valid_input_char(c: char) -> bool

Source§

impl SpinValue for f64

Source§

fn to_f64(self) -> f64

Source§

fn from_f64_saturating(v: f64) -> Self

Source§

fn parse(s: &str) -> Option<Self>

Source§

fn format(self, decimals: u8) -> String

Source§

fn saturating_add(self, rhs: Self) -> Self

Source§

fn saturating_sub(self, rhs: Self) -> Self

Source§

fn saturating_mul_u32(self, rhs: u32) -> Self

Source§

fn is_integer() -> bool

Source§

fn is_valid_input_char(c: char) -> bool

Source§

impl SpinValue for i32

Source§

fn to_f64(self) -> f64

Source§

fn from_f64_saturating(v: f64) -> Self

Source§

fn parse(s: &str) -> Option<Self>

Source§

fn format(self, _decimals: u8) -> String

Source§

fn saturating_add(self, rhs: Self) -> Self

Source§

fn saturating_sub(self, rhs: Self) -> Self

Source§

fn saturating_mul_u32(self, rhs: u32) -> Self

Source§

fn is_integer() -> bool

Source§

fn is_valid_input_char(c: char) -> bool

Source§

impl SpinValue for i64

Source§

fn to_f64(self) -> f64

Source§

fn from_f64_saturating(v: f64) -> Self

Source§

fn parse(s: &str) -> Option<Self>

Source§

fn format(self, _decimals: u8) -> String

Source§

fn saturating_add(self, rhs: Self) -> Self

Source§

fn saturating_sub(self, rhs: Self) -> Self

Source§

fn saturating_mul_u32(self, rhs: u32) -> Self

Source§

fn is_integer() -> bool

Source§

fn is_valid_input_char(c: char) -> bool

Source§

impl SpinValue for u8

Source§

fn to_f64(self) -> f64

Source§

fn from_f64_saturating(v: f64) -> Self

Source§

fn parse(s: &str) -> Option<Self>

Source§

fn format(self, _decimals: u8) -> String

Source§

fn saturating_add(self, rhs: Self) -> Self

Source§

fn saturating_sub(self, rhs: Self) -> Self

Source§

fn saturating_mul_u32(self, rhs: u32) -> Self

Source§

fn is_integer() -> bool

Source§

fn is_valid_input_char(c: char) -> bool

Source§

impl SpinValue for u32

Source§

fn to_f64(self) -> f64

Source§

fn from_f64_saturating(v: f64) -> Self

Source§

fn parse(s: &str) -> Option<Self>

Source§

fn format(self, _decimals: u8) -> String

Source§

fn saturating_add(self, rhs: Self) -> Self

Source§

fn saturating_sub(self, rhs: Self) -> Self

Source§

fn saturating_mul_u32(self, rhs: u32) -> Self

Source§

fn is_integer() -> bool

Source§

fn is_valid_input_char(c: char) -> bool

Source§

impl SpinValue for u64

Source§

fn to_f64(self) -> f64

Source§

fn from_f64_saturating(v: f64) -> Self

Source§

fn parse(s: &str) -> Option<Self>

Source§

fn format(self, _decimals: u8) -> String

Source§

fn saturating_add(self, rhs: Self) -> Self

Source§

fn saturating_sub(self, rhs: Self) -> Self

Source§

fn saturating_mul_u32(self, rhs: u32) -> Self

Source§

fn is_integer() -> bool

Source§

fn is_valid_input_char(c: char) -> bool

Source§

impl SpinValue for usize

Source§

fn to_f64(self) -> f64

Source§

fn from_f64_saturating(v: f64) -> Self

Source§

fn parse(s: &str) -> Option<Self>

Source§

fn format(self, _decimals: u8) -> String

Source§

fn saturating_add(self, rhs: Self) -> Self

Source§

fn saturating_sub(self, rhs: Self) -> Self

Source§

fn saturating_mul_u32(self, rhs: u32) -> Self

Source§

fn is_integer() -> bool

Source§

fn is_valid_input_char(c: char) -> bool

Implementors§