Skip to main content

Counter

Struct Counter 

Source
pub struct Counter { /* private fields */ }
Expand description

A bounded reactive counter.

Constructed via Counter::new(min, max, step) (Lombok New); the counter starts at i32::default() (0). Use Counter::set (or one of the mutator methods) to set the initial value. The current value is exposed as a Signal<i32> accessed through get_value(). Mutators (increment, decrement, set, reset) write through that signal, so any render closure that reads counter.get_value().get() re-renders when the value changes.

Implementations§

Source§

impl Counter

Inherent implementation of Counter.

Source

pub fn increment(&self)

Adds step to the value, clamping into [min, max] afterwards. If the counter is already at max, the value is left at max.

Source

pub fn decrement(&self)

Subtracts step from the value, clamping into [min, max] afterwards. If the counter is already at min, the value is left at min.

Source

pub fn set(&self, next: i32)

Replaces the value with next, clamping into [min, max] if bounds are set.

§Arguments
  • i32 - A 32-bit signed integer (i32).
Source

pub fn set_unchecked(&self, next: i32)

Replaces the value with next without clamping. Bypasses both the min and max bounds. Use when you genuinely want to push the counter outside its configured range (e.g., to “reset to a deliberately out-of-range sentinel” or to recover from an invalid configuration).

§Arguments
  • i32 - A 32-bit signed integer (i32).
Source

pub fn is_at_max(&self) -> bool

Returns true when the value is at the configured max (or always false if unbounded above).

§Returns
  • bool - true when the value is at the configured maximum.
Source

pub fn is_at_min(&self) -> bool

Returns true when the value is at the configured min (or always false if unbounded below).

§Returns
  • bool - true when the value is at the configured minimum.
Source

pub fn get(&self) -> i32

Returns the current value as a snapshot.

§Returns
  • i32 - The current value (or a snapshot thereof).
Source§

impl Counter

Source

pub fn get_value(&self) -> &Signal<i32>

Source

pub fn get_mut_value(&mut self) -> &mut Signal<i32>

Source

pub fn set_value(&mut self, val: Signal<i32>) -> &mut Self

Source

pub fn get_min(&self) -> i32

Source

pub fn try_get_min(&self) -> &Option<i32>

Source

pub fn get_mut_min(&mut self) -> &mut Option<i32>

Source

pub fn set_min(&mut self, val: Option<i32>) -> &mut Self

Source

pub fn get_max(&self) -> i32

Source

pub fn try_get_max(&self) -> &Option<i32>

Source

pub fn get_mut_max(&mut self) -> &mut Option<i32>

Source

pub fn set_max(&mut self, val: Option<i32>) -> &mut Self

Source

pub fn get_step(&self) -> &i32

Source

pub fn get_mut_step(&mut self) -> &mut i32

Source

pub fn set_step(&mut self, val: i32) -> &mut Self

Source§

impl Counter

Source

pub fn new(min: Option<i32>, max: Option<i32>, step: i32) -> Self

Trait Implementations§

Source§

impl Clone for Counter

Source§

fn clone(&self) -> Counter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Counter

Source§

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

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

impl Default for Counter

Source§

fn default() -> Counter

Returns the “default value” for a type. Read more
Source§

impl Display for Counter

Formatting / debug-printing for Counter.

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult

Formats the Counter via the supplied formatter.

§Arguments
  • &mut Formatter<'_> - The formatter receiving the formatted output.
§Returns
  • FmtResult - Result of the formatting operation.

Auto Trait Implementations§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more