[][src]Struct num_format::format::Environment

pub struct Environment { /* fields omitted */ }

Type for representing formats from the LC_ALL environment variable.

Example

use std::env;

use failure;
use num_format::{format::Environment, ToFormattedString};

fn main() -> Result<(), failure::Error> {
    // Use your system's default locale settings
    let format = Environment::new()?;
    let s = (-1000000).to_formatted_string(&format);
    println!("{}", &s);

    // Use your system's locale settings for "en_US.UTF-8"
    env::set_var("LC_ALL", "en_US.UTF-8");
    let format = Environment::new()?;
    let s = (-1000000).to_formatted_string(&format);
    assert_eq!("-1,000,000", &s);

    Ok(())
}

Methods

impl Environment[src]

pub fn new() -> Result<Environment, Error>[src]

Constructs a new Environment.

Note

  • This method uses the setlocale and localeconv API from C in order to access your system's locale settings specified by the LC_ALL environment variable.
  • Because representations of infinity and NaN are not specified in locale files, English representations from the Unicode Common Locale Data Repository (CLDR) are used for these values, which are "∞" (U+221E) and "NaN". You can change these with calls to the set_infinity and set_nan methods.

Errors

Return an error if any of the calls into C fail (e.g. if localeconv return a NULL pointer).

pub fn decimal(&self) -> char[src]

Returns this format's representation of decimal points.

pub fn grouping(&self) -> Grouping[src]

Returns this format's Grouping, which governs how digits are separated (see Grouping).

pub fn infinity(&self) -> &str[src]

Returns this format's representation of infinity.

pub fn minus_sign(&self) -> &str[src]

Returns this format's representation of minus signs.

pub fn nan(&self) -> &str[src]

Returns this format's representation of NaN.

pub fn separator(&self) -> Option<char>[src]

Returns this format's representation of separators.

pub fn set_infinity<S>(&mut self, value: S) -> Result<(), Error> where
    S: AsRef<str>, 
[src]

Sets the string used for infinity.

Errors

Return an error if the length is greater than 64 bytes.

pub fn set_nan<S>(&mut self, value: S) -> Result<(), Error> where
    S: AsRef<str>, 
[src]

Sets the string used for NaN.

Errors

Return an error if the length is greater than 64 bytes.

Trait Implementations

impl Format for Environment[src]

impl Eq for Environment[src]

impl Clone for Environment[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Copy for Environment[src]

impl PartialEq<Environment> for Environment[src]

impl Hash for Environment[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Debug for Environment[src]

Auto Trait Implementations

impl Send for Environment

impl Sync for Environment

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]