# Feature request: Stabilize \`NumBufferTrait\` to use as a bound

**URL:** <https://internals.rust-lang.org/t/feature-request-stabilize-numbuffertrait-to-use-as-a-bound/24581>\
**Category:** libs\
**Created:** [September 8, 2026, 3:20pm UTC](https://internals.rust-lang.org/t/feature-request-stabilize-numbuffertrait-to-use-as-a-bound/24581 "2026-09-08T15:20:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tyilo](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tyilo/32/10642_2.png) [@tyilo](https://internals.rust-lang.org/u/tyilo)\
**Post date:** [September 8, 2026, 3:20pm UTC](https://internals.rust-lang.org/t/feature-request-stabilize-numbuffertrait-to-use-as-a-bound/24581/1 "2026-09-08T15:20:24Z")

</div>

I would like to add the [`format_into`](https://doc.rust-lang.org/stable/std/primitive.u32.html#method.format_into) function to my [`Integer`](https://docs.rs/std-traits/latest/std_traits/num/trait.Integer.html) trait.

This doesn't seem to be possible because of the `T: NumBufferTrait` bound in the definition of [`NumBuffer`](https://doc.rust-lang.org/stable/core/fmt/struct.NumBuffer.html) which requires me to add [`NumBufferTrait`](https://doc.rust-lang.org/stable/core/fmt/trait.NumBufferTrait.html) as a super bound to `Integer`.

If `NumBufferTrait` could be used as a bound, this would allow me to implement this function.

A similar issue exists with the [`to_int_unchecked`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.to_int_unchecked) function and the [`FloatToInt`](https://doc.rust-lang.org/stable/std/convert/trait.FloatToInt.html) trait.

---

<div class="post-metadata">

**Author:** ![chrefr](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@chrefr](https://internals.rust-lang.org/u/chrefr)\
**Post date:** [September 8, 2026, 3:47pm UTC](https://internals.rust-lang.org/t/feature-request-stabilize-numbuffertrait-to-use-as-a-bound/24581/2 "2026-09-08T15:47:41Z")

</div>

You're implementing your trait with a macro, right? You can just have the buffer as an associated type.

---

<div class="post-metadata">

**Author:** ![tyilo](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tyilo/32/10642_2.png) [@tyilo](https://internals.rust-lang.org/u/tyilo)\
**Post date:** [September 8, 2026, 4:19pm UTC](https://internals.rust-lang.org/t/feature-request-stabilize-numbuffertrait-to-use-as-a-bound/24581/3 "2026-09-08T16:19:46Z")

</div>

Yeah, you're right that I could do something like:

```rust
use core::fmt::NumBuffer;

trait MyNumBuffer {
    fn new() -> Self;
}

trait Integer {
    type NumBuffer: MyNumBuffer;

    fn format_into(self, buf: &mut Self::NumBuffer) -> &str;
}

impl MyNumBuffer for NumBuffer<u32> {
    fn new() -> Self {
        NumBuffer::new()
    }
}

impl Integer for u32 {
    type NumBuffer = NumBuffer<Self>;

    fn format_into(self, buf: &mut Self::NumBuffer) -> &str {
        Self::format_into(self, buf)
    }
}

fn print_int<T: Integer>(value: T) {
    let mut buf = T::NumBuffer::new();
    let formatted = value.format_into(&mut buf);
    println!("{}", formatted);
}

fn main() {
    print_int(1234);
}

```

However that requires defining my own `MyNumBuffer` trait ☹

---

<div class="post-metadata">

**Author:** ![cuviper](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cuviper/32/1897_2.png) [@cuviper](https://internals.rust-lang.org/u/cuviper)\
**Post date:** [September 8, 2026, 5:21pm UTC](https://internals.rust-lang.org/t/feature-request-stabilize-numbuffertrait-to-use-as-a-bound/24581/4 "2026-09-08T17:21:38Z")

</div>

I do the same thing in `num-primitive`:

> **[type NumBuffer: PrimitiveNumBuffer - PrimitiveInteger in num\_primitive - Rust](https://docs.rs/num-primitive/latest/num_primitive/trait.PrimitiveInteger.html#associatedtype.NumBuffer)**
>
> The buffer type for format\_into. | Trait for all primitive integer types, including the supertrait \`PrimitiveNumber\`.

---

<div class="post-metadata">

**Author:** ![tyilo](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tyilo/32/10642_2.png) [@tyilo](https://internals.rust-lang.org/u/tyilo)\
**Post date:** [September 8, 2026, 8:19pm UTC](https://internals.rust-lang.org/t/feature-request-stabilize-numbuffertrait-to-use-as-a-bound/24581/5 "2026-09-08T20:19:45Z")

</div>

Actually if `NumBuffer` implemented `Default` I wouldn't need the extra trait. It also seem like it should implement `Default` anyways.

---

<div class="post-metadata">

**Author:** ![kpreid](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kpreid/32/8484_2.png) [@kpreid](https://internals.rust-lang.org/u/kpreid)\
**Post date:** [September 8, 2026, 8:55pm UTC](https://internals.rust-lang.org/t/feature-request-stabilize-numbuffertrait-to-use-as-a-bound/24581/6 "2026-09-08T20:55:15Z")

</div>

I expect that a PR to implement `Default` would be simple and uncontroversial.

---

<div class="post-metadata">

**Author:** ![tyilo](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tyilo/32/10642_2.png) [@tyilo](https://internals.rust-lang.org/u/tyilo)\
**Post date:** [September 9, 2026, 1:26pm UTC](https://internals.rust-lang.org/t/feature-request-stabilize-numbuffertrait-to-use-as-a-bound/24581/7 "2026-09-09T13:26:34Z")

</div>

> <https://github.com/rust-lang/rust/pull/162536>
>
> Discussed a bit in https://internals.rust-lang.org/t/feature-request-stabilize-n…umbuffertrait-to-use-as-a-bound/24581/
