Skip to content

Commit 31b6484

Browse files
committed
Made all fns const
1 parent a76e1f6 commit 31b6484

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

library/core/src/fmt/mod.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl FormattingOptions {
294294
/// - no precision, and
295295
/// - no [`DebugAsHex`] output mode.
296296
#[unstable(feature = "formatting_options", issue = "118117")]
297-
pub fn new() -> Self {
297+
pub const fn new() -> Self {
298298
Self {
299299
sign: None,
300300
sign_aware_zero_pad: false,
@@ -316,15 +316,15 @@ impl FormattingOptions {
316316
/// always be printed.
317317
/// - `-`: Currently not used
318318
#[unstable(feature = "formatting_options", issue = "118117")]
319-
pub fn sign(&mut self, sign: Option<Sign>) -> &mut Self {
319+
pub const fn sign(&mut self, sign: Option<Sign>) -> &mut Self {
320320
self.sign = sign;
321321
self
322322
}
323323
/// Sets or unsets the `0` flag.
324324
///
325325
/// 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
326326
#[unstable(feature = "formatting_options", issue = "118117")]
327-
pub fn sign_aware_zero_pad(&mut self, sign_aware_zero_pad: bool) -> &mut Self {
327+
pub const fn sign_aware_zero_pad(&mut self, sign_aware_zero_pad: bool) -> &mut Self {
328328
self.sign_aware_zero_pad = sign_aware_zero_pad;
329329
self
330330
}
@@ -337,7 +337,7 @@ impl FormattingOptions {
337337
/// - [`Octal`] - precedes the argument with a `0b`
338338
/// - [`Binary`] - precedes the argument with a `0o`
339339
#[unstable(feature = "formatting_options", issue = "118117")]
340-
pub fn alternate(&mut self, alternate: bool) -> &mut Self {
340+
pub const fn alternate(&mut self, alternate: bool) -> &mut Self {
341341
self.alternate = alternate;
342342
self
343343
}
@@ -348,7 +348,7 @@ impl FormattingOptions {
348348
/// being formatted is smaller than width some extra characters will be
349349
/// printed around it.
350350
#[unstable(feature = "formatting_options", issue = "118117")]
351-
pub fn fill(&mut self, fill: char) -> &mut Self {
351+
pub const fn fill(&mut self, fill: char) -> &mut Self {
352352
self.fill = fill;
353353
self
354354
}
@@ -357,7 +357,7 @@ impl FormattingOptions {
357357
/// The alignment specifies how the value being formatted should be
358358
/// positioned if it is smaller than the width of the formatter.
359359
#[unstable(feature = "formatting_options", issue = "118117")]
360-
pub fn align(&mut self, align: Option<Alignment>) -> &mut Self {
360+
pub const fn align(&mut self, align: Option<Alignment>) -> &mut Self {
361361
self.align = align;
362362
self
363363
}
@@ -368,7 +368,7 @@ impl FormattingOptions {
368368
/// the padding specified by [`FormattingOptions::fill`]/[`FormattingOptions::align`]
369369
/// will be used to take up the required space.
370370
#[unstable(feature = "formatting_options", issue = "118117")]
371-
pub fn width(&mut self, width: Option<usize>) -> &mut Self {
371+
pub const fn width(&mut self, width: Option<usize>) -> &mut Self {
372372
self.width = width;
373373
self
374374
}
@@ -382,64 +382,64 @@ impl FormattingOptions {
382382
/// - For floating-point types, this indicates how many digits after the
383383
/// decimal point should be printed.
384384
#[unstable(feature = "formatting_options", issue = "118117")]
385-
pub fn precision(&mut self, precision: Option<usize>) -> &mut Self {
385+
pub const fn precision(&mut self, precision: Option<usize>) -> &mut Self {
386386
self.precision = precision;
387387
self
388388
}
389389
/// Specifies whether the [`Debug`] trait should use lower-/upper-case
390390
/// hexadecimal or normal integers
391391
#[unstable(feature = "formatting_options", issue = "118117")]
392-
pub fn debug_as_hex(&mut self, debug_as_hex: Option<DebugAsHex>) -> &mut Self {
392+
pub const fn debug_as_hex(&mut self, debug_as_hex: Option<DebugAsHex>) -> &mut Self {
393393
self.debug_as_hex = debug_as_hex;
394394
self
395395
}
396396

397397
/// Returns the current sign (the `+` or the `-` flag).
398398
#[unstable(feature = "formatting_options", issue = "118117")]
399-
pub fn get_sign(&self) -> Option<Sign> {
399+
pub const fn get_sign(&self) -> Option<Sign> {
400400
self.sign
401401
}
402402
/// Returns the current `0` flag.
403403
#[unstable(feature = "formatting_options", issue = "118117")]
404-
pub fn get_sign_aware_zero_pad(&self) -> bool {
404+
pub const fn get_sign_aware_zero_pad(&self) -> bool {
405405
self.sign_aware_zero_pad
406406
}
407407
/// Returns the current `#` flag.
408408
#[unstable(feature = "formatting_options", issue = "118117")]
409-
pub fn get_alternate(&self) -> bool {
409+
pub const fn get_alternate(&self) -> bool {
410410
self.alternate
411411
}
412412
/// Returns the current fill character.
413413
#[unstable(feature = "formatting_options", issue = "118117")]
414-
pub fn get_fill(&self) -> char {
414+
pub const fn get_fill(&self) -> char {
415415
self.fill
416416
}
417417
/// Returns the current alignment.
418418
#[unstable(feature = "formatting_options", issue = "118117")]
419-
pub fn get_align(&self) -> Option<Alignment> {
419+
pub const fn get_align(&self) -> Option<Alignment> {
420420
self.align
421421
}
422422
/// Returns the current width.
423423
#[unstable(feature = "formatting_options", issue = "118117")]
424-
pub fn get_width(&self) -> Option<usize> {
424+
pub const fn get_width(&self) -> Option<usize> {
425425
self.width
426426
}
427427
/// Returns the current precision.
428428
#[unstable(feature = "formatting_options", issue = "118117")]
429-
pub fn get_precision(&self) -> Option<usize> {
429+
pub const fn get_precision(&self) -> Option<usize> {
430430
self.precision
431431
}
432432
/// Returns the current precision.
433433
#[unstable(feature = "formatting_options", issue = "118117")]
434-
pub fn get_debug_as_hex(&self) -> Option<DebugAsHex> {
434+
pub const fn get_debug_as_hex(&self) -> Option<DebugAsHex> {
435435
self.debug_as_hex
436436
}
437437

438438
/// Creates a [`Formatter`] that writes its output to the given [`Write`] trait.
439439
///
440440
/// You may alternatively use [`Formatter::new()`].
441441
#[unstable(feature = "formatting_options", issue = "118117")]
442-
pub fn create_formatter<'a>(self, write: &'a mut (dyn Write + 'a)) -> Formatter<'a> {
442+
pub const fn create_formatter<'a>(self, write: &'a mut (dyn Write + 'a)) -> Formatter<'a> {
443443
Formatter { options: self, buf: write }
444444
}
445445

@@ -508,13 +508,13 @@ impl<'a> Formatter<'a> {
508508
///
509509
/// You may alternatively use [`FormattingOptions::create_formatter()`].
510510
#[unstable(feature = "formatting_options", issue = "118117")]
511-
pub fn new(write: &'a mut (dyn Write + 'a), options: FormattingOptions) -> Self {
511+
pub const fn new(write: &'a mut (dyn Write + 'a), options: FormattingOptions) -> Self {
512512
Formatter { options, buf: write }
513513
}
514514

515515
/// Creates a new formatter based on this one with given [`FormattingOptions`].
516516
#[unstable(feature = "formatting_options", issue = "118117")]
517-
pub fn with_options<'b>(&'b mut self, options: FormattingOptions) -> Formatter<'b> {
517+
pub const fn with_options<'b>(&'b mut self, options: FormattingOptions) -> Formatter<'b> {
518518
Formatter { options, buf: self.buf }
519519
}
520520
}
@@ -2494,13 +2494,13 @@ impl<'a> Formatter<'a> {
24942494

24952495
/// Returns the sign of this formatter (`+` or `-`).
24962496
#[unstable(feature = "formatting_options", issue = "118117")]
2497-
pub fn sign(&self) -> Option<Sign> {
2497+
pub const fn sign(&self) -> Option<Sign> {
24982498
self.options.get_sign()
24992499
}
25002500

25012501
/// Returns the formatting options this formatter corresponds to.
25022502
#[unstable(feature = "formatting_options", issue = "118117")]
2503-
pub fn options(&self) -> FormattingOptions {
2503+
pub const fn options(&self) -> FormattingOptions {
25042504
self.options
25052505
}
25062506
}

0 commit comments

Comments
 (0)