Skip to main content

Formatter

Enum Formatter 

Source
pub enum Formatter {
    Float {
        precision: usize,
    },
    Decibel {
        precision: usize,
    },
    DecibelDirect {
        precision: usize,
        min_db: f64,
    },
    Frequency,
    Milliseconds {
        precision: usize,
    },
    Seconds {
        precision: usize,
    },
    Percent {
        precision: usize,
    },
    Pan,
    Ratio {
        precision: usize,
    },
    Semitones,
    Boolean,
}
Expand description

Parameter value formatter.

Defines how plain parameter values are converted to display strings and parsed back from user input.

Variants§

§

Float

Generic float with configurable precision (e.g., “1.23”).

Fields

§precision: usize

Number of decimal places.

§

Decibel

Decibel formatter for gain/level parameters.

Input is linear amplitude (0.0 = silence, 1.0 = unity). Format: “-12.0”, “-inf” (unit “dB” via unit())

Fields

§precision: usize

Number of decimal places.

§

DecibelDirect

Direct decibel formatter where input is already in dB.

Used by FloatParameter::db() where the plain value is stored as dB. Format: “+12.0”, “-60.0” (unit “dB” via unit())

Fields

§precision: usize

Number of decimal places.

§min_db: f64

Minimum dB value (below this shows “-inf”)

§

Frequency

Frequency formatter with automatic Hz/kHz scaling.

Format: “440”, “1.50k” (unit “Hz” via unit())

§

Milliseconds

Milliseconds formatter.

Format: “10.0” (unit “ms” via unit())

Fields

§precision: usize

Number of decimal places.

§

Seconds

Seconds formatter.

Format: “1.50” (unit “s” via unit())

Fields

§precision: usize

Number of decimal places.

§

Percent

Percentage formatter.

Input is 0.0-1.0, display is 0-100. Format: “75” (unit “%” via unit())

Fields

§precision: usize

Number of decimal places.

§

Pan

Pan formatter for stereo position.

Input is -1.0 (left) to +1.0 (right). Display: “L50”, “C”, “R50”

§

Ratio

Ratio formatter for compressors.

Display: “4.0:1”, “∞:1”

Fields

§precision: usize

Number of decimal places.

§

Semitones

Semitones formatter for pitch shifting.

Format: “+12”, “-7”, “0” (unit “st” via unit())

§

Boolean

Boolean formatter.

Display: “On”, “Off”

Implementations§

Source§

impl Formatter

Source

pub fn text(&self, value: f64) -> String

Convert a plain value to a display string (without unit).

The interpretation of value depends on the formatter variant:

  • Decibel: linear amplitude (1.0 = 0 dB)
  • Frequency: Hz
  • Milliseconds: ms
  • Seconds: s
  • Percent: 0.0-1.0 (displayed as 0-100)
  • Pan: -1.0 to +1.0
  • Ratio: ratio value (4.0 = “4:1”)
  • Semitones: integer semitones
  • Boolean: >0.5 = On, <=0.5 = Off
Source

pub fn parse(&self, s: &str) -> Option<f64>

Parse a display string to a plain value.

Returns None if the string cannot be parsed. Accepts various formats with or without units.

Source

pub fn unit(&self) -> &'static str

Get the unit string for this formatter.

Source§

impl Formatter

Source

pub fn with_precision(self, precision: usize) -> Self

Return a new Formatter with updated precision.

For formatter variants that have a precision field, this returns a new formatter with the updated precision. For variants without precision (e.g., Pan, Boolean, Semitones, Frequency), this returns self unchanged.

§Example
let formatter = Formatter::DecibelDirect { precision: 1, min_db: -60.0 };
let high_precision = formatter.with_precision(3);
// high_precision is DecibelDirect { precision: 3, min_db: -60.0 }

let pan = Formatter::Pan;
let same_pan = pan.with_precision(2);
// same_pan is still Pan (no precision field)
Source

pub fn supports_precision(&self) -> bool

Check if this formatter variant supports precision customization.

Returns true for variants with a precision field, false otherwise.

Source

pub fn precision(&self) -> Option<usize>

Get the current precision, if applicable.

Returns Some(precision) for variants with a precision field, None otherwise.

Trait Implementations§

Source§

impl Clone for Formatter

Source§

fn clone(&self) -> Formatter

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Formatter

Source§

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

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

impl Default for Formatter

Source§

fn default() -> Self

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

impl PartialEq for Formatter

Source§

fn eq(&self, other: &Formatter) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Formatter

Source§

impl StructuralPartialEq for Formatter

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.