Skip to content

Commit 575a90e

Browse files
committed
formatting_options: Make all methods const
Having `const fn`s that take a `mut &` was unstable until Rust 1.83. Because of this, not all methods on `FormattingOptions` were implemented as `const`. As this has been stabilized now, there is no reason not to have all methods `const`. Thanks to Ternvein for bringing this to my attention (see [1]). [1]: #118117 (comment)
1 parent 54c5812 commit 575a90e

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

‎library/core/src/fmt/mod.rs‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl FormattingOptions {
359359
/// always be printed.
360360
/// - `-`: Currently not used
361361
#[unstable(feature = "formatting_options", issue = "118117")]
362-
pubfnsign(&mutself,sign:Option<Sign>) -> &mutSelf{
362+
pubconstfnsign(&mutself,sign:Option<Sign>) -> &mutSelf{
363363
let sign = match sign {
364364
None => 0,
365365
Some(Sign::Plus) => flags::SIGN_PLUS_FLAG,
@@ -372,7 +372,7 @@ impl FormattingOptions {
372372
///
373373
/// This is used to indicate for integer formats that the padding to width should both be done with a 0 character as well as be sign-aware
374374
#[unstable(feature = "formatting_options", issue = "118117")]
375-
pubfnsign_aware_zero_pad(&mutself,sign_aware_zero_pad:bool) -> &mutSelf{
375+
pubconstfnsign_aware_zero_pad(&mutself,sign_aware_zero_pad:bool) -> &mutSelf{
376376
if sign_aware_zero_pad {
377377
self.flags |= flags::SIGN_AWARE_ZERO_PAD_FLAG;
378378
}else{
@@ -389,7 +389,7 @@ impl FormattingOptions {
389389
/// - [`Octal`] - precedes the argument with a `0b`
390390
/// - [`Binary`] - precedes the argument with a `0o`
391391
#[unstable(feature = "formatting_options", issue = "118117")]
392-
pubfnalternate(&mutself,alternate:bool) -> &mutSelf{
392+
pubconstfnalternate(&mutself,alternate:bool) -> &mutSelf{
393393
if alternate {
394394
self.flags |= flags::ALTERNATE_FLAG;
395395
}else{
@@ -404,7 +404,7 @@ impl FormattingOptions {
404404
/// being formatted is smaller than width some extra characters will be
405405
/// printed around it.
406406
#[unstable(feature = "formatting_options", issue = "118117")]
407-
pubfnfill(&mutself,fill:char) -> &mutSelf{
407+
pubconstfnfill(&mutself,fill:char) -> &mutSelf{
408408
self.flags = self.flags&(u32::MAX << 21) | fill asu32;
409409
self
410410
}
@@ -413,7 +413,7 @@ impl FormattingOptions {
413413
/// The alignment specifies how the value being formatted should be
414414
/// positioned if it is smaller than the width of the formatter.
415415
#[unstable(feature = "formatting_options", issue = "118117")]
416-
pubfnalign(&mutself,align:Option<Alignment>) -> &mutSelf{
416+
pubconstfnalign(&mutself,align:Option<Alignment>) -> &mutSelf{
417417
let align:u32 = match align {
418418
Some(Alignment::Left) => flags::ALIGN_LEFT,
419419
Some(Alignment::Right) => flags::ALIGN_RIGHT,
@@ -430,7 +430,7 @@ impl FormattingOptions {
430430
/// the padding specified by [`FormattingOptions::fill`]/[`FormattingOptions::align`]
431431
/// will be used to take up the required space.
432432
#[unstable(feature = "formatting_options", issue = "118117")]
433-
pubfnwidth(&mutself,width:Option<u16>) -> &mutSelf{
433+
pubconstfnwidth(&mutself,width:Option<u16>) -> &mutSelf{
434434
ifletSome(width) = width {
435435
self.flags |= flags::WIDTH_FLAG;
436436
self.width = width;
@@ -450,7 +450,7 @@ impl FormattingOptions {
450450
/// - For floating-point types, this indicates how many digits after the
451451
/// decimal point should be printed.
452452
#[unstable(feature = "formatting_options", issue = "118117")]
453-
pubfnprecision(&mutself,precision:Option<u16>) -> &mutSelf{
453+
pubconstfnprecision(&mutself,precision:Option<u16>) -> &mutSelf{
454454
ifletSome(precision) = precision {
455455
self.flags |= flags::PRECISION_FLAG;
456456
self.precision = precision;
@@ -463,7 +463,7 @@ impl FormattingOptions {
463463
/// Specifies whether the [`Debug`] trait should use lower-/upper-case
464464
/// hexadecimal or normal integers
465465
#[unstable(feature = "formatting_options", issue = "118117")]
466-
pubfndebug_as_hex(&mutself,debug_as_hex:Option<DebugAsHex>) -> &mutSelf{
466+
pubconstfndebug_as_hex(&mutself,debug_as_hex:Option<DebugAsHex>) -> &mutSelf{
467467
let debug_as_hex = match debug_as_hex {
468468
None => 0,
469469
Some(DebugAsHex::Lower) => flags::DEBUG_LOWER_HEX_FLAG,
@@ -537,7 +537,7 @@ impl FormattingOptions {
537537
///
538538
/// You may alternatively use [`Formatter::new()`].
539539
#[unstable(feature = "formatting_options", issue = "118117")]
540-
pubfncreate_formatter<'a>(self,write:&'amut(dynWrite + 'a)) -> Formatter<'a>{
540+
pubconstfncreate_formatter<'a>(self,write:&'amut(dynWrite + 'a)) -> Formatter<'a>{
541541
Formatter{options:self,buf: write }
542542
}
543543
}
@@ -578,13 +578,13 @@ impl<'a> Formatter<'a> {
578578
///
579579
/// You may alternatively use [`FormattingOptions::create_formatter()`].
580580
#[unstable(feature = "formatting_options", issue = "118117")]
581-
pubfnnew(write:&'amut(dynWrite + 'a),options:FormattingOptions) -> Self{
581+
pubconstfnnew(write:&'amut(dynWrite + 'a),options:FormattingOptions) -> Self{
582582
Formatter{ options,buf: write }
583583
}
584584

585585
/// Creates a new formatter based on this one with given [`FormattingOptions`].
586586
#[unstable(feature = "formatting_options", issue = "118117")]
587-
pubfnwith_options<'b>(&'bmutself,options:FormattingOptions) -> Formatter<'b>{
587+
pubconstfnwith_options<'b>(&'bmutself,options:FormattingOptions) -> Formatter<'b>{
588588
Formatter{ options,buf:self.buf}
589589
}
590590
}

0 commit comments

Comments
 (0)