[][src]Trait thousands::Separable

pub trait Separable {
    fn separate_by_policy(&self, policy: SeparatorPolicy) -> String;

    fn separate_with_commas(&self) -> String { ... }
fn separate_with_spaces(&self) -> String { ... }
fn separate_with_dots(&self) -> String { ... }
fn separate_with_underscores(&self) -> String { ... } }

Provides methods for formatting numbers with separators between the digits.

Required methods

fn separate_by_policy(&self, policy: SeparatorPolicy) -> String

Adds separators according to the given SeparatorPolicy.

Examples

use thousands::{Separable, SeparatorPolicy, digits};

let policy = SeparatorPolicy {
    separator:  ":",
    groups:     &[1, 2, 3, 4],
    digits:     digits::ASCII_DECIMAL,
};

assert_eq!( 1234567654321u64.separate_by_policy(policy),
            "123:4567:654:32:1" );
Loading content...

Provided methods

fn separate_with_commas(&self) -> String

Inserts a comma every three digits from the right.

This is equivalent to self.separate_by_policy(policies::COMMA_SEPARATOR).

Examples

assert_eq!( 12345.separate_with_commas(), "12,345" );

fn separate_with_spaces(&self) -> String

Inserts a space every three digits from the right.

This is equivalent to self.separate_by_policy(policies::SPACE_SEPARATOR).

Examples

assert_eq!( 12345.separate_with_spaces(), "12 345" );

fn separate_with_dots(&self) -> String

Inserts a period every three digits from the right.

This is equivalent to self.separate_by_policy(policies::DOT_SEPARATOR).

Examples

assert_eq!( 12345.separate_with_dots(), "12.345" );

fn separate_with_underscores(&self) -> String

Inserts an underscore every three digits from the right.

This is equivalent to self.separate_by_policy(policies::UNDERSCORE_SEPARATOR).

Examples

assert_eq!( 12345.separate_with_underscores(), "12_345" );
Loading content...

Implementations on Foreign Types

impl Separable for str[src]

Loading content...

Implementors

impl<T: Display> Separable for T[src]

Loading content...