Struct icu_experimental::dimension::percent::formatter::PercentFormatter
source · pub struct PercentFormatter<R> { /* private fields */ }
Expand description
A formatter for percent values.
PercentFormatter
supports:
- Rendering in the locale’s percent system.
Implementations§
source§impl PercentFormatter<FixedDecimalFormatter>
impl PercentFormatter<FixedDecimalFormatter>
sourcepub fn try_new_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
prefs: PercentFormatterPreferences,
options: PercentFormatterOptions,
) -> Result<Self, DataError>
pub fn try_new_with_any_provider( provider: &(impl AnyProvider + ?Sized), prefs: PercentFormatterPreferences, options: PercentFormatterOptions, ) -> Result<Self, 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: PercentFormatterPreferences,
options: PercentFormatterOptions,
) -> Result<Self, DataError>
pub fn try_new_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), prefs: PercentFormatterPreferences, options: PercentFormatterOptions, ) -> Result<Self, 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: PercentFormatterPreferences,
options: PercentFormatterOptions,
) -> Result<Self, DataError>
pub fn try_new( prefs: PercentFormatterPreferences, options: PercentFormatterOptions, ) -> Result<Self, DataError>
Creates a new PercentFormatter
from compiled locale data and an options bag.
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_unstable<D>(
provider: &D,
prefs: PercentFormatterPreferences,
options: PercentFormatterOptions,
) -> Result<Self, DataError>where
D: ?Sized + DataProvider<PercentEssentialsV1Marker> + DataProvider<DecimalSymbolsV2Marker> + DataProvider<DecimalDigitsV1Marker>,
pub fn try_new_unstable<D>(
provider: &D,
prefs: PercentFormatterPreferences,
options: PercentFormatterOptions,
) -> Result<Self, DataError>where
D: ?Sized + DataProvider<PercentEssentialsV1Marker> + DataProvider<DecimalSymbolsV2Marker> + DataProvider<DecimalDigitsV1Marker>,
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<'l>(
&'l self,
value: &'l SignedFixedDecimal,
) -> FormattedPercent<'l>
pub fn format<'l>( &'l self, value: &'l SignedFixedDecimal, ) -> FormattedPercent<'l>
Formats a [SignedFixedDecimal
] value for the given percent code.
§Examples
use icu::experimental::dimension::percent::formatter::PercentFormatter;
use icu::locale::locale;
use writeable::Writeable;
let locale = locale!("en-US").into();
let fmt = PercentFormatter::try_new(locale, Default::default()).unwrap();
let value = "12345.67".parse().unwrap();
let formatted_percent = fmt.format(&value);
let mut sink = String::new();
formatted_percent.write_to(&mut sink).unwrap();
assert_eq!(sink.as_str(), "12,345.67%");
source§impl<R> PercentFormatter<R>where
R: AsRef<FixedDecimalFormatter>,
impl<R> PercentFormatter<R>where
R: AsRef<FixedDecimalFormatter>,
sourcepub fn try_new_with_fixed_decimal_formatter(
prefs: PercentFormatterPreferences,
fixed_decimal_formatter: R,
options: PercentFormatterOptions,
) -> Result<Self, DataError>
pub fn try_new_with_fixed_decimal_formatter( prefs: PercentFormatterPreferences, fixed_decimal_formatter: R, options: PercentFormatterOptions, ) -> Result<Self, DataError>
Creates a new PercentFormatter
from compiled locale data, an options bag and fixed decimal formatter.
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_with_fixed_decimal_formatter_unstable(
provider: &(impl DataProvider<PercentEssentialsV1Marker> + ?Sized),
prefs: PercentFormatterPreferences,
fixed_decimal_formatter: R,
options: PercentFormatterOptions,
) -> Result<Self, DataError>
pub fn try_new_with_fixed_decimal_formatter_unstable( provider: &(impl DataProvider<PercentEssentialsV1Marker> + ?Sized), prefs: PercentFormatterPreferences, fixed_decimal_formatter: R, options: PercentFormatterOptions, ) -> Result<Self, 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.
Auto Trait Implementations§
impl<R> Freeze for PercentFormatter<R>where
R: Freeze,
impl<R> RefUnwindSafe for PercentFormatter<R>where
R: RefUnwindSafe,
impl<R> Send for PercentFormatter<R>where
R: Send,
impl<R> Sync for PercentFormatter<R>where
R: Sync,
impl<R> Unpin for PercentFormatter<R>where
R: Unpin,
impl<R> UnwindSafe for PercentFormatter<R>where
R: UnwindSafe,
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