@@ -310,7 +310,7 @@ impl FormattingOptions {
310
310
/// - no precision, and
311
311
/// - no [`DebugAsHex`] output mode.
312
312
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
313
- pub fn new ( ) -> Self {
313
+ pub const fn new ( ) -> Self {
314
314
Self {
315
315
sign : None ,
316
316
sign_aware_zero_pad : false ,
@@ -332,15 +332,15 @@ impl FormattingOptions {
332
332
/// always be printed.
333
333
/// - `-`: Currently not used
334
334
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
335
- pub fn sign ( & mut self , sign : Option < Sign > ) -> & mut Self {
335
+ pub const fn sign ( & mut self , sign : Option < Sign > ) -> & mut Self {
336
336
self . sign = sign;
337
337
self
338
338
}
339
339
/// Sets or unsets the `0` flag.
340
340
///
341
341
/// 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
342
342
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
343
- pub fn sign_aware_zero_pad ( & mut self , sign_aware_zero_pad : bool ) -> & mut Self {
343
+ pub const fn sign_aware_zero_pad ( & mut self , sign_aware_zero_pad : bool ) -> & mut Self {
344
344
self . sign_aware_zero_pad = sign_aware_zero_pad;
345
345
self
346
346
}
@@ -353,7 +353,7 @@ impl FormattingOptions {
353
353
/// - [`Octal`] - precedes the argument with a `0b`
354
354
/// - [`Binary`] - precedes the argument with a `0o`
355
355
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
356
- pub fn alternate ( & mut self , alternate : bool ) -> & mut Self {
356
+ pub const fn alternate ( & mut self , alternate : bool ) -> & mut Self {
357
357
self . alternate = alternate;
358
358
self
359
359
}
@@ -364,7 +364,7 @@ impl FormattingOptions {
364
364
/// being formatted is smaller than width some extra characters will be
365
365
/// printed around it.
366
366
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
367
- pub fn fill ( & mut self , fill : char ) -> & mut Self {
367
+ pub const fn fill ( & mut self , fill : char ) -> & mut Self {
368
368
self . fill = fill;
369
369
self
370
370
}
@@ -373,7 +373,7 @@ impl FormattingOptions {
373
373
/// The alignment specifies how the value being formatted should be
374
374
/// positioned if it is smaller than the width of the formatter.
375
375
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
376
- pub fn align ( & mut self , align : Option < Alignment > ) -> & mut Self {
376
+ pub const fn align ( & mut self , align : Option < Alignment > ) -> & mut Self {
377
377
self . align = align;
378
378
self
379
379
}
@@ -384,7 +384,7 @@ impl FormattingOptions {
384
384
/// the padding specified by [`FormattingOptions::fill`]/[`FormattingOptions::align`]
385
385
/// will be used to take up the required space.
386
386
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
387
- pub fn width ( & mut self , width : Option < usize > ) -> & mut Self {
387
+ pub const fn width ( & mut self , width : Option < usize > ) -> & mut Self {
388
388
self . width = width;
389
389
self
390
390
}
@@ -398,64 +398,64 @@ impl FormattingOptions {
398
398
/// - For floating-point types, this indicates how many digits after the
399
399
/// decimal point should be printed.
400
400
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
401
- pub fn precision ( & mut self , precision : Option < usize > ) -> & mut Self {
401
+ pub const fn precision ( & mut self , precision : Option < usize > ) -> & mut Self {
402
402
self . precision = precision;
403
403
self
404
404
}
405
405
/// Specifies whether the [`Debug`] trait should use lower-/upper-case
406
406
/// hexadecimal or normal integers
407
407
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
408
- pub fn debug_as_hex ( & mut self , debug_as_hex : Option < DebugAsHex > ) -> & mut Self {
408
+ pub const fn debug_as_hex ( & mut self , debug_as_hex : Option < DebugAsHex > ) -> & mut Self {
409
409
self . debug_as_hex = debug_as_hex;
410
410
self
411
411
}
412
412
413
413
/// Returns the current sign (the `+` or the `-` flag).
414
414
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
415
- pub fn get_sign ( & self ) -> Option < Sign > {
415
+ pub const fn get_sign ( & self ) -> Option < Sign > {
416
416
self . sign
417
417
}
418
418
/// Returns the current `0` flag.
419
419
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
420
- pub fn get_sign_aware_zero_pad ( & self ) -> bool {
420
+ pub const fn get_sign_aware_zero_pad ( & self ) -> bool {
421
421
self . sign_aware_zero_pad
422
422
}
423
423
/// Returns the current `#` flag.
424
424
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
425
- pub fn get_alternate ( & self ) -> bool {
425
+ pub const fn get_alternate ( & self ) -> bool {
426
426
self . alternate
427
427
}
428
428
/// Returns the current fill character.
429
429
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
430
- pub fn get_fill ( & self ) -> char {
430
+ pub const fn get_fill ( & self ) -> char {
431
431
self . fill
432
432
}
433
433
/// Returns the current alignment.
434
434
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
435
- pub fn get_align ( & self ) -> Option < Alignment > {
435
+ pub const fn get_align ( & self ) -> Option < Alignment > {
436
436
self . align
437
437
}
438
438
/// Returns the current width.
439
439
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
440
- pub fn get_width ( & self ) -> Option < usize > {
440
+ pub const fn get_width ( & self ) -> Option < usize > {
441
441
self . width
442
442
}
443
443
/// Returns the current precision.
444
444
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
445
- pub fn get_precision ( & self ) -> Option < usize > {
445
+ pub const fn get_precision ( & self ) -> Option < usize > {
446
446
self . precision
447
447
}
448
448
/// Returns the current precision.
449
449
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
450
- pub fn get_debug_as_hex ( & self ) -> Option < DebugAsHex > {
450
+ pub const fn get_debug_as_hex ( & self ) -> Option < DebugAsHex > {
451
451
self . debug_as_hex
452
452
}
453
453
454
454
/// Creates a [`Formatter`] that writes its output to the given [`Write`] trait.
455
455
///
456
456
/// You may alternatively use [`Formatter::new()`].
457
457
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
458
- pub fn create_formatter < ' a > ( self , write : & ' a mut ( dyn Write + ' a ) ) -> Formatter < ' a > {
458
+ pub const fn create_formatter < ' a > ( self , write : & ' a mut ( dyn Write + ' a ) ) -> Formatter < ' a > {
459
459
Formatter { options : self , buf : write }
460
460
}
461
461
@@ -524,13 +524,13 @@ impl<'a> Formatter<'a> {
524
524
///
525
525
/// You may alternatively use [`FormattingOptions::create_formatter()`].
526
526
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
527
- pub fn new ( write : & ' a mut ( dyn Write + ' a ) , options : FormattingOptions ) -> Self {
527
+ pub const fn new ( write : & ' a mut ( dyn Write + ' a ) , options : FormattingOptions ) -> Self {
528
528
Formatter { options, buf : write }
529
529
}
530
530
531
531
/// Creates a new formatter based on this one with given [`FormattingOptions`].
532
532
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
533
- pub fn with_options < ' b > ( & ' b mut self , options : FormattingOptions ) -> Formatter < ' b > {
533
+ pub const fn with_options < ' b > ( & ' b mut self , options : FormattingOptions ) -> Formatter < ' b > {
534
534
Formatter { options, buf : self . buf }
535
535
}
536
536
}
@@ -2584,13 +2584,13 @@ impl<'a> Formatter<'a> {
2584
2584
2585
2585
/// Returns the sign of this formatter (`+` or `-`).
2586
2586
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
2587
- pub fn sign ( & self ) -> Option < Sign > {
2587
+ pub const fn sign ( & self ) -> Option < Sign > {
2588
2588
self . options . get_sign ( )
2589
2589
}
2590
2590
2591
2591
/// Returns the formatting options this formatter corresponds to.
2592
2592
#[ unstable( feature = "formatting_options" , issue = "118117" ) ]
2593
- pub fn options ( & self ) -> FormattingOptions {
2593
+ pub const fn options ( & self ) -> FormattingOptions {
2594
2594
self . options
2595
2595
}
2596
2596
}
0 commit comments