Struct icu::experimental::dimension::currency::long_compact_formatter::LongCompactCurrencyFormatter
source · pub struct LongCompactCurrencyFormatter { /* private fields */ }
Expand description
A formatter for monetary values.
LongCompactCurrencyFormatter
supports:
- Rendering in the locale’s currency system.
- Locale-sensitive grouping separator positions.
Implementations§
source§impl LongCompactCurrencyFormatter
impl LongCompactCurrencyFormatter
sourcepub fn try_new_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
prefs: LongCompactCurrencyFormatterPreferences,
currency_code: &CurrencyCode,
) -> Result<LongCompactCurrencyFormatter, DataError>
pub fn try_new_with_any_provider( provider: &(impl AnyProvider + ?Sized), prefs: LongCompactCurrencyFormatterPreferences, currency_code: &CurrencyCode, ) -> Result<LongCompactCurrencyFormatter, DataError>
A version of [Self :: try_new
] that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized),
prefs: LongCompactCurrencyFormatterPreferences,
currency_code: &CurrencyCode,
) -> Result<LongCompactCurrencyFormatter, DataError>
pub fn try_new_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), prefs: LongCompactCurrencyFormatterPreferences, currency_code: &CurrencyCode, ) -> Result<LongCompactCurrencyFormatter, DataError>
A version of [Self :: try_new
] that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
sourcepub fn try_new(
prefs: LongCompactCurrencyFormatterPreferences,
currency_code: &CurrencyCode,
) -> Result<LongCompactCurrencyFormatter, DataError>
pub fn try_new( prefs: LongCompactCurrencyFormatterPreferences, currency_code: &CurrencyCode, ) -> Result<LongCompactCurrencyFormatter, DataError>
Creates a new LongCompactCurrencyFormatter
from compiled locale data.
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_unstable<D>(
provider: &D,
prefs: LongCompactCurrencyFormatterPreferences,
currency_code: &CurrencyCode,
) -> Result<LongCompactCurrencyFormatter, DataError>
pub fn try_new_unstable<D>( provider: &D, prefs: LongCompactCurrencyFormatterPreferences, currency_code: &CurrencyCode, ) -> Result<LongCompactCurrencyFormatter, DataError>
A version of Self::try_new
that uses custom data provided by a DataProvider
.
⚠️ The bounds on provider may change over time, including in SemVer minor releases.
sourcepub fn format_fixed_decimal<'l>(
&'l self,
value: &'l Signed<UnsignedFixedDecimal>,
currency_code: CurrencyCode,
) -> FormattedLongCompactCurrency<'l>
pub fn format_fixed_decimal<'l>( &'l self, value: &'l Signed<UnsignedFixedDecimal>, currency_code: CurrencyCode, ) -> FormattedLongCompactCurrency<'l>
Formats in the long format a SignedFixedDecimal
value for the given currency code.
§Examples
use icu::experimental::dimension::currency::long_compact_formatter::LongCompactCurrencyFormatter;
use icu::experimental::dimension::currency::CurrencyCode;
use icu::locale::locale;
use tinystr::*;
use writeable::Writeable;
let currency_prefs = locale!("en-US").into();
let currency_code = CurrencyCode(tinystr!(3, "USD"));
let fmt = LongCompactCurrencyFormatter::try_new(currency_prefs, ¤cy_code).unwrap();
let value = "12345.67".parse().unwrap();
let formatted_currency = fmt.format_fixed_decimal(&value, currency_code);
let mut sink = String::new();
formatted_currency.write_to(&mut sink).unwrap();
assert_eq!(sink.as_str(), "12 thousand US dollars");
Auto Trait Implementations§
impl Freeze for LongCompactCurrencyFormatter
impl RefUnwindSafe for LongCompactCurrencyFormatter
impl Send for LongCompactCurrencyFormatter
impl Sync for LongCompactCurrencyFormatter
impl Unpin for LongCompactCurrencyFormatter
impl UnwindSafe for LongCompactCurrencyFormatter
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more