# Would it ever be possible to add a blanket implementations like this to stdlib?

**URL:** <https://internals.rust-lang.org/t/would-it-ever-be-possible-to-add-a-blanket-implementations-like-this-to-stdlib/22694>\
**Category:** libs\
**Created:** [April 4, 2025, 5:13pm UTC](https://internals.rust-lang.org/t/would-it-ever-be-possible-to-add-a-blanket-implementations-like-this-to-stdlib/22694 "2025-04-04T17:13:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![HjVT](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hjvt/32/10365_2.png) [@HjVT](https://internals.rust-lang.org/u/HjVT)\
**Post date:** [April 4, 2025, 5:13pm UTC](https://internals.rust-lang.org/t/would-it-ever-be-possible-to-add-a-blanket-implementations-like-this-to-stdlib/22694/1 "2025-04-04T17:13:12Z")

</div>

`impl<A, B> [Try]From<A> for Option<B> where B: [Try]From<A>`

It certainly ia not an infrequent occurrence to perform an operation like that, but while in normal code it is possible to just map the container type, it is not always possible, for example in some derive annotations like `sqlx`'s `FromRow` derive's `#[try_from(Type)]` annotation.

---

<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:** [April 4, 2025, 7:26pm UTC](https://internals.rust-lang.org/t/would-it-ever-be-possible-to-add-a-blanket-implementations-like-this-to-stdlib/22694/2 "2025-04-04T19:26:48Z")

</div>

The immediate problem is that this overlaps with `impl<T> From<T> for T`, because `A` and `B` may be the same type. I don't know if specialization or the like can ever solve that.

---

<div class="post-metadata">

**Author:** ![JarredAllen](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@JarredAllen](https://internals.rust-lang.org/u/JarredAllen)\
**Post date:** [April 7, 2025, 5:31pm UTC](https://internals.rust-lang.org/t/would-it-ever-be-possible-to-add-a-blanket-implementations-like-this-to-stdlib/22694/3 "2025-04-07T17:31:00Z")

</div>

I think specialization could solve that (we'd need a specialized `[Try]From Option<B> for Option<B>` to cover the overlap), and specialization would also be required to avoid this being a big breaking change. Right now, one could write (not only can you write this, I'd guess this is what OP should write to get their code working):

```rust
struct Foo { .. }
struct Bar { .. }

impl TryFrom<Foo> for Bar { .. }
impl TryFrom<Foo> for Option<Bar> { .. }

```

And with OP's blanket impl but without specialization, this is a conflict that would cause the code to compile error.

---

<div class="post-metadata">

**Author:** ![HjVT](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hjvt/32/10365_2.png) [@HjVT](https://internals.rust-lang.org/u/HjVT)\
**Post date:** [April 7, 2025, 6:18pm UTC](https://internals.rust-lang.org/t/would-it-ever-be-possible-to-add-a-blanket-implementations-like-this-to-stdlib/22694/4 "2025-04-07T18:18:49Z")

</div>

The construction I'm wishing it was possible to avoid is as follows:

```rust
use foo_crate::Foo;

struct FooProxy(..);
struct FooProxyOptional(..);

impl TryFrom<FooProxy> for Foo { .. }
impl TryFrom<FooProxyOptional> for Option<Foo> { .. }

```

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [September 29, 2026, 6:19pm UTC](https://internals.rust-lang.org/t/would-it-ever-be-possible-to-add-a-blanket-implementations-like-this-to-stdlib/22694/5 "2026-09-29T18:19:07Z")

</div>

Closed on September 29, 2026, 6:19pm UTC

This topic was automatically closed 540 days after the last reply. New replies are no longer allowed.
