Skip to content

Commit 9e5a25b

Browse files
authored
Breaking: change format_fixed_decimal to accept a reference to SignedFixedDecimal (#5882)
1 parent e7c271a commit 9e5a25b

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

components/experimental/src/compactdecimal/formatter.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl CompactDecimalFormatter {
315315
/// ```
316316
pub fn format_i64(&self, value: i64) -> FormattedCompactDecimal<'_> {
317317
let unrounded = SignedFixedDecimal::from(value);
318-
self.format_fixed_decimal(unrounded)
318+
self.format_fixed_decimal(&unrounded)
319319
}
320320

321321
/// Formats a floating-point number in compact decimal notation using the default
@@ -380,7 +380,7 @@ impl CompactDecimalFormatter {
380380
// NOTE: This first gets the shortest representation of the f64, which
381381
// manifests as double rounding.
382382
let partly_rounded = SignedFixedDecimal::try_from_f64(value, RoundTrip)?;
383-
Ok(self.format_fixed_decimal(partly_rounded))
383+
Ok(self.format_fixed_decimal(&partly_rounded))
384384
}
385385

386386
/// Formats a [`SignedFixedDecimal`] by automatically scaling and rounding it.
@@ -406,38 +406,38 @@ impl CompactDecimalFormatter {
406406
/// .unwrap();
407407
///
408408
/// assert_writeable_eq!(
409-
/// short_english.format_fixed_decimal(SignedFixedDecimal::from(0)),
409+
/// short_english.format_fixed_decimal(&SignedFixedDecimal::from(0)),
410410
/// "0"
411411
/// );
412412
/// assert_writeable_eq!(
413-
/// short_english.format_fixed_decimal(SignedFixedDecimal::from(2)),
413+
/// short_english.format_fixed_decimal(&SignedFixedDecimal::from(2)),
414414
/// "2"
415415
/// );
416416
/// assert_writeable_eq!(
417-
/// short_english.format_fixed_decimal(SignedFixedDecimal::from(843)),
417+
/// short_english.format_fixed_decimal(&SignedFixedDecimal::from(843)),
418418
/// "843"
419419
/// );
420420
/// assert_writeable_eq!(
421-
/// short_english.format_fixed_decimal(SignedFixedDecimal::from(2207)),
421+
/// short_english.format_fixed_decimal(&SignedFixedDecimal::from(2207)),
422422
/// "2.2K"
423423
/// );
424424
/// assert_writeable_eq!(
425-
/// short_english.format_fixed_decimal(SignedFixedDecimal::from(15127)),
425+
/// short_english.format_fixed_decimal(&SignedFixedDecimal::from(15127)),
426426
/// "15K"
427427
/// );
428428
/// assert_writeable_eq!(
429-
/// short_english.format_fixed_decimal(SignedFixedDecimal::from(3010349)),
429+
/// short_english.format_fixed_decimal(&SignedFixedDecimal::from(3010349)),
430430
/// "3M"
431431
/// );
432432
/// assert_writeable_eq!(
433-
/// short_english.format_fixed_decimal(SignedFixedDecimal::from(-13132)),
433+
/// short_english.format_fixed_decimal(&SignedFixedDecimal::from(-13132)),
434434
/// "-13K"
435435
/// );
436436
///
437437
/// // The sign display on the FixedDecimal is respected:
438438
/// assert_writeable_eq!(
439439
/// short_english.format_fixed_decimal(
440-
/// SignedFixedDecimal::from(2500)
440+
/// &SignedFixedDecimal::from(2500)
441441
/// .with_sign_display(fixed_decimal::SignDisplay::ExceptZero)
442442
/// ),
443443
/// "+2.5K"
@@ -457,31 +457,31 @@ impl CompactDecimalFormatter {
457457
/// # Default::default(),
458458
/// # ).unwrap();
459459
/// assert_writeable_eq!(
460-
/// short_english.format_fixed_decimal("999499.99".parse().unwrap()),
460+
/// short_english.format_fixed_decimal(&"999499.99".parse().unwrap()),
461461
/// "999K"
462462
/// );
463463
/// assert_writeable_eq!(
464-
/// short_english.format_fixed_decimal("999500.00".parse().unwrap()),
464+
/// short_english.format_fixed_decimal(&"999500.00".parse().unwrap()),
465465
/// "1M"
466466
/// );
467467
/// assert_writeable_eq!(
468-
/// short_english.format_fixed_decimal("1650".parse().unwrap()),
468+
/// short_english.format_fixed_decimal(&"1650".parse().unwrap()),
469469
/// "1.6K"
470470
/// );
471471
/// assert_writeable_eq!(
472-
/// short_english.format_fixed_decimal("1750".parse().unwrap()),
472+
/// short_english.format_fixed_decimal(&"1750".parse().unwrap()),
473473
/// "1.8K"
474474
/// );
475475
/// assert_writeable_eq!(
476-
/// short_english.format_fixed_decimal("1950".parse().unwrap()),
476+
/// short_english.format_fixed_decimal(&"1950".parse().unwrap()),
477477
/// "2K"
478478
/// );
479479
/// assert_writeable_eq!(
480-
/// short_english.format_fixed_decimal("-1172700".parse().unwrap()),
480+
/// short_english.format_fixed_decimal(&"-1172700".parse().unwrap()),
481481
/// "-1.2M"
482482
/// );
483483
/// ```
484-
pub fn format_fixed_decimal(&self, value: SignedFixedDecimal) -> FormattedCompactDecimal<'_> {
484+
pub fn format_fixed_decimal(&self, value: &SignedFixedDecimal) -> FormattedCompactDecimal<'_> {
485485
let log10_type = value.absolute.nonzero_magnitude_start();
486486
let (mut plural_map, mut exponent) = self.plural_map_and_exponent_for_magnitude(log10_type);
487487
let mut significand = value.clone();

0 commit comments

Comments
 (0)