Skip to main content

NumericFormat

Struct NumericFormat 

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

Immutable scientific numeric presentation with explicitly selected locale.

Rounding defaults to nearest with ties to even, after exact decimal scaling. Affixes are literal: a percent suffix alone does not scale the scientific value. Adaptive precision is selected uniformly for each complete semantic set, independently of geometric fit. The default is Decimal/Fractional(2), scale zero, absent affixes, preserved negative zero and retained trailing zeros.

use lichtung_plot::{NumericFormat, NumericValues, Plot, formatting::{NumericNotation, NumericPrecision}};
let percent = NumericFormat::new(NumericNotation::Decimal, NumericPrecision::Fractional(1))?
    .decimal_scale(2)?
    .suffix("%")?;
assert_eq!(percent.get_decimal_scale(), 2);
let plot = Plot::scatter(NumericValues::new("x", [1.0, 2.0]),
                         NumericValues::new("rate", [0.125, 0.875]))
    .y_tick_format(percent);

Fields and the implementation module stay private:

ⓘ
use lichtung_plot::NumericFormat;
let _ = NumericFormat::default().decimal_scale;
ⓘ
use lichtung_plot::numeric::format::NumericFormat;

Precision edits take an explicit precision policy:

ⓘ
use lichtung_plot::NumericFormat;
let _ = NumericFormat::default().precision(2);

Implementations§

Source§

impl NumericFormat

Source

pub fn new( notation: NumericNotation, precision: NumericPrecision, ) -> Result<Self>

Construct a validated format with scale zero, no affixes, Preserve, Keep and NearestEven rounding.

Source

pub const fn get_notation(&self) -> NumericNotation

The selected decimal/exponent notation.

Source

pub const fn get_precision(&self) -> NumericPrecision

The exact precision or complete adaptive bounds.

Source

pub const fn get_decimal_scale(&self) -> i16

The exact signed decimal display shift, from -324 through 324.

Source

pub fn get_prefix(&self) -> Option<&str>

Literal text before the sign and number, or absence.

Source

pub fn get_suffix(&self) -> Option<&str>

Literal text immediately after the number, or absence.

Source

pub const fn get_negative_zero(&self) -> NegativeZero

Actual and rounded negative-zero handling.

Source

pub const fn get_trailing_zeros(&self) -> TrailingZeros

Fractional trailing-zero handling.

Source

pub fn notation(self, value: NumericNotation) -> Result<Self>

Replace notation while retaining and validating every other field.

Source

pub fn precision(self, value: NumericPrecision) -> Result<Self>

Replace precision; fractional bounds are 0..=20 and significant bounds 1..=21. Adaptive min must not exceed max.

Source

pub fn decimal_scale(self, value: i16) -> Result<Self>

Replace the exact decimal display shift within -324..=324. This never changes scientific coordinates or color mapping.

Source

pub fn prefix(self, value: impl Into<String>) -> Result<Self>

Replace the literal prefix with nonempty, control-free text. Spaces and combining marks are preserved exactly.

Source

pub fn suffix(self, value: impl Into<String>) -> Result<Self>

Replace the literal suffix with nonempty, control-free text. No scaling or spacing is inferred from its contents.

Source

pub fn negative_zero(self, value: NegativeZero) -> Result<Self>

Replace handling of actual or rounded negative zero.

Source

pub fn trailing_zeros(self, value: TrailingZeros) -> Result<Self>

Replace fractional zero trimming; integral place-value zeros are retained.

Source

pub fn rounding(self, value: NumericRounding) -> Result<Self>

Replace exact rounding at the selected decimal quantum. Signed floor/ceiling and tie handling apply before negative-zero normalization.

Source

pub fn multiplier(self, value: f64) -> Result<Self>

Multiply by the exact represented finite factor before the one rounding. Negative factors reverse display signs; either signed zero selects zero.

Source

pub fn locale(self, value: NumericLocale) -> Result<Self>

Select complete explicit locale tokens, without host inference.

Source

pub fn grouping(self, value: bool) -> Result<Self>

Enable integer grouping using the selected locale’s optional pattern.

Source

pub fn sign(self, value: NumericSign) -> Result<Self>

Select sign presentation, after numeric rounding and zero normalization.

Source

pub fn symbol(self, value: NumericSymbol) -> Result<Self>

Select currency or an applicable nondecimal integer-radix prefix.

Source

pub fn field(self, value: Option<NumericField>) -> Result<Self>

Set or clear minimum Unicode-scalar field width.

Source

pub fn rate(self, value: NumericRate) -> Result<Self>

Select an exact rate factor and the locale’s automatic suffix.

Source

pub fn prefixes(self, value: NumericPrefixes) -> Result<Self>

Replace the sole SI, compact or common exact-divisor policy.

Source§

impl NumericFormat

Source

pub fn value_function<F>(self, function: F) -> Self
where F: for<'a> Fn(&NumericValueContext<'a>) -> Result<String> + Send + Sync + 'static,

Select final per-occurrence text, retaining built-in options for helpers.

Source

pub fn set_function<F>(self, function: F) -> Self
where F: for<'a> Fn(&NumericSetContext<'a>) -> Result<NumericLabels> + Send + Sync + 'static,

Select final complete-set text and optional common explanatory Text.

Source

pub fn builtin(self) -> Self

Restore built-in emission without resetting any normalized options.

Source§

impl NumericFormat

Source

pub fn from_specifier(specifier: &str) -> Result<Self>

Compile [[fill]align][sign][symbol][0][width][,][.precision][~][type]. Numeric types are f/e/g/r/s/%/p/d/b/o/x/X/n or omitted; unknown types and text coercion reject. Exact renderer rounding is not JavaScript arithmetic.

Source§

impl NumericFormat

Source

pub fn unit(self, value: Option<NumericUnit>) -> Result<Self>

Set or clear literal unit text, validating its single-line tokens.

Source

pub fn explanation(self, value: NumericExplanation) -> Self

Replace instructions/content for the one common explanation slot.

Trait Implementations§

Source§

impl Clone for NumericFormat

Source§

fn clone(&self) -> Self

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 NumericFormat

Source§

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

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

impl Default for NumericFormat

Source§

fn default() -> Self

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

impl Eq for NumericFormat

Source§

impl PartialEq for NumericFormat

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for NumericFormat

Auto Trait Implementations§

§

impl !RefUnwindSafe for NumericFormat

§

impl !UnwindSafe for NumericFormat

§

impl Forget for NumericFormat

§

impl Freeze for NumericFormat
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const ArcInner<LocaleData> is !null: Freeze, PhantomData<ArcInner<LocaleData>>: Freeze, *const ArcInner<PrefixMode> is !null: Freeze, PhantomData<ArcInner<PrefixMode>>: Freeze, *const ArcInner<UnitPolicy> is !null: Freeze, PhantomData<ArcInner<UnitPolicy>>: Freeze, *const ArcInner<Function> is !null: Freeze, PhantomData<ArcInner<Function>>: Freeze,

§

impl Move for NumericFormat

§

impl Send for NumericFormat
where RawVecInner: Send, Arc<LocaleData>: Send, Arc<PrefixMode>: Send, Arc<UnitPolicy>: Send, Arc<Function>: Send,

§

impl Sync for NumericFormat
where RawVecInner: Sync, Arc<LocaleData>: Sync, Arc<PrefixMode>: Sync, Arc<UnitPolicy>: Sync, Arc<Function>: Sync,

§

impl Unpin for NumericFormat
where *const u8 is !null: Unpin, Arc<LocaleData>: Unpin, Arc<PrefixMode>: Unpin, Arc<UnitPolicy>: Unpin, Arc<Function>: Unpin,

§

impl UnsafeUnpin for NumericFormat
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const ArcInner<LocaleData> is !null: UnsafeUnpin, PhantomData<ArcInner<LocaleData>>: UnsafeUnpin, *const ArcInner<PrefixMode> is !null: UnsafeUnpin, PhantomData<ArcInner<PrefixMode>>: UnsafeUnpin, *const ArcInner<UnitPolicy> is !null: UnsafeUnpin, PhantomData<ArcInner<UnitPolicy>>: UnsafeUnpin, *const ArcInner<Function> is !null: UnsafeUnpin, PhantomData<ArcInner<Function>>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V