pub struct AmountFieldOptions {
pub locale: String,
pub fraction_digits: u8,
pub allow_negative: bool,
}Expand description
Locale and precision of an amount, like lumen-core’s LumenAmountOptions.
Fields§
§locale: StringBCP 47 locale of the separators and digits. Defaults to en-US.
fraction_digits: u8Allowed fraction digits, from 0 to 20. Defaults to 2.
allow_negative: boolWhether negative amounts are accepted. Defaults to false.
Implementations§
Source§impl AmountFieldOptions
impl AmountFieldOptions
Sourcepub fn format_draft(&self, draft: &str) -> Result<String, AmountFieldError>
pub fn format_draft(&self, draft: &str) -> Result<String, AmountFieldError>
Formats an ASCII draft for display, like formatLumenAmountDraft: the integer is grouped
with the locale’s separators and digits, leading integer zeros are dropped, and fraction
digits (including trailing zeros) are kept exactly.
§Errors
AmountFieldError::FractionDigits for invalid options and AmountFieldError::Draft
when the draft is not a valid draft for them.
Sourcepub fn parse_draft(&self, source: &str, strict_grouping: bool) -> Option<String>
pub fn parse_draft(&self, source: &str, strict_grouping: bool) -> Option<String>
Parses displayed or pasted text back to an ASCII draft, like parseLumenAmountDraft.
Accepts the locale’s digits and ASCII digits, its decimal separator, - or the locale’s
minus sign, group separators, and bidirectional marks. With strict_grouping (pasted
text), group separators must sit exactly where the locale puts them. A leading decimal
separator gains a zero (.5 becomes 0.5). Returns None for anything else, including
text longer than 1024 UTF-16 code units and invalid options.
Trait Implementations§
Source§impl Clone for AmountFieldOptions
impl Clone for AmountFieldOptions
Source§impl Debug for AmountFieldOptions
impl Debug for AmountFieldOptions
Source§impl Default for AmountFieldOptions
impl Default for AmountFieldOptions
impl Eq for AmountFieldOptions
Source§impl PartialEq for AmountFieldOptions
impl PartialEq for AmountFieldOptions
impl StructuralPartialEq for AmountFieldOptions
Auto Trait Implementations§
impl Forget for AmountFieldOptions
impl Freeze for AmountFieldOptions
impl Move for AmountFieldOptions
impl RefUnwindSafe for AmountFieldOptions
impl Send for AmountFieldOptionswhere
RawVecInner: Send,
impl Sync for AmountFieldOptionswhere
RawVecInner: Sync,
impl Unpin for AmountFieldOptions
impl UnsafeUnpin for AmountFieldOptions
impl UnwindSafe for AmountFieldOptionswhere
RawVecInner: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DependencyElement for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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> ⓘ
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> ⓘ
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