pub struct DisplayContext { /* private fields */ }Expand description
Display context for formatting numbers with consistent precision per currency.
Tracks the maximum number of decimal places seen for each currency during parsing, and provides methods to format numbers with that precision.
Implementations§
Source§impl DisplayContext
impl DisplayContext
Sourcepub fn update(&mut self, number: Decimal, currency: &str)
pub fn update(&mut self, number: Decimal, currency: &str)
Update the display context with a number for a currency.
This records the decimal precision of the number (number of digits after the decimal point) and updates the maximum precision seen for that currency.
Sourcepub fn update_from(&mut self, other: &Self)
pub fn update_from(&mut self, other: &Self)
Update the display context from another display context.
Takes the maximum precision for each currency from both contexts.
Sourcepub const fn set_render_commas(&mut self, render_commas: bool)
pub const fn set_render_commas(&mut self, render_commas: bool)
Set the render_commas flag.
Sourcepub const fn render_commas(&self) -> bool
pub const fn render_commas(&self) -> bool
Get the render_commas flag.
Sourcepub fn set_fixed_precision(&mut self, currency: &str, precision: u32)
pub fn set_fixed_precision(&mut self, currency: &str, precision: u32)
Set a fixed precision for a currency (from option "display_precision").
Fixed precision takes precedence over inferred precision.
Sourcepub fn get_precision(&self, currency: &str) -> Option<u32>
pub fn get_precision(&self, currency: &str) -> Option<u32>
Get the precision for a currency.
Returns the fixed precision if set, otherwise the maximum precision seen, or None if the currency has never been seen.
Sourcepub fn format(&self, number: Decimal, currency: &str) -> String
pub fn format(&self, number: Decimal, currency: &str) -> String
Format a decimal number for a currency using the tracked precision.
If the currency has been seen, formats with the maximum precision. Otherwise, formats with the number’s natural precision (no trailing zeros). Uses half-up rounding to match Python beancount behavior.
Sourcepub fn format_amount(&self, number: Decimal, currency: &str) -> String
pub fn format_amount(&self, number: Decimal, currency: &str) -> String
Format an amount (number + currency) using the tracked precision.
Trait Implementations§
Source§impl Clone for DisplayContext
impl Clone for DisplayContext
Source§fn clone(&self) -> DisplayContext
fn clone(&self) -> DisplayContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DisplayContext
impl Debug for DisplayContext
Source§impl Default for DisplayContext
impl Default for DisplayContext
Source§fn default() -> DisplayContext
fn default() -> DisplayContext
Auto Trait Implementations§
impl Freeze for DisplayContext
impl RefUnwindSafe for DisplayContext
impl Send for DisplayContext
impl Sync for DisplayContext
impl Unpin for DisplayContext
impl UnwindSafe for DisplayContext
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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,
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.