From de28a95577ab43e7635ca1b9edc40ccdb9fa46c7 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 19 May 2026 07:15:07 -0400 Subject: [PATCH] Add an example to the `NumBuffer` documentations We specifically call out that the sign is written for negative integers. This would also ideally be called out in `::format_into`, but the macro infrastructure for the implementation unfortunately doesn't really make this easy as far as I can tell. --- library/core/src/fmt/num_buffer.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/library/core/src/fmt/num_buffer.rs b/library/core/src/fmt/num_buffer.rs index 055c50833d94..cc3680b8a42b 100644 --- a/library/core/src/fmt/num_buffer.rs +++ b/library/core/src/fmt/num_buffer.rs @@ -34,6 +34,22 @@ impl NumBufferTrait for $unsigned { /// A buffer wrapper of which the internal size is based on the maximum /// number of digits the associated integer can have. +/// +/// # Examples +/// +/// ``` +/// #![feature(int_format_into)] +/// use core::fmt::NumBuffer; +/// +/// let mut buf = NumBuffer::new(); +/// let n1 = 1972u32; +/// assert_eq!(n1.format_into(&mut buf), "1972"); +/// +/// // Formatting a negative integer includes the sign. +/// let mut buf = NumBuffer::new(); +/// let n2 = -1972i32; +/// assert_eq!(n2.format_into(&mut buf), "-1972"); +/// ``` #[unstable(feature = "int_format_into", issue = "138215")] pub struct NumBuffer { // FIXME: Once const generics feature is working, use `T::BUF_SIZE` instead of 40.