# Limited Opt Out of Orphan Rule

**URL:** <https://internals.rust-lang.org/t/limited-opt-out-of-orphan-rule/21709>\
**Category:** language design\
**Created:** [October 15, 2024, 1:08pm UTC](https://internals.rust-lang.org/t/limited-opt-out-of-orphan-rule/21709 "2024-10-15T13:08:34Z")\
**Posts on this page:** 1\
**Showing post:** 20

<div class="post-metadata">

**Author:** ![zackw](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/zackw/32/2071_2.png) [@zackw](https://internals.rust-lang.org/u/zackw)\
**Post date:** [October 24, 2024, 4:01pm UTC](https://internals.rust-lang.org/t/limited-opt-out-of-orphan-rule/21709/20 "2024-10-24T16:01:13Z")

</div>

Concrete example of your first case: I have a project right now that uses [`rustix`](https://docs.rs/rustix/latest/rustix/) and [`unix_path`](https://docs.rs/unix_path/latest/unix_path/) in a no-std context. (It's a fully hosted environment; no-std is only being used to avoid a dependency on the C runtime.) Because `rustix` and `unix_path` are independent crates, neither of them provides an impl of [`rustix::path::Arg`](https://docs.rs/rustix/latest/rustix/path/trait.Arg.html) for [`unix_path::UnixPath`](https://docs.rs/unix_path/latest/unix_path/struct.Path.html), and the orphan rule prevents me from providing one, which means I have to write `path.as_unix_str().as_bytes()` every time I want to pass a path to a rustix function, which is often.

(It's my impression that this sort of thing is _the_ most important reason why people want to relax the orphan rule. I _could_ work around this with a newtype over `UnixPath`, but getting its ergonomics to match `UnixPath`'s would be more work than continuing to type `path.as_unix_str().as_bytes()` all over the place.)

* * *

This is not technically about the orphan rule, but it's a closely related possible language feature that would require us to solve many of the same problems: Sometimes a crate might wish to _override_ the implementation of a trait by one of its dependencies. This same project provides a good example: In a no-std configuration, rustix's `Display` impl for [`rustix::io::Errno`](https://docs.rs/rustix/latest/rustix/io/struct.Errno.html) prints "os error \<number\>" for all errors, which is not exactly user friendly; I'd ideally like to override it with an impl that provides the usual human-readable error strings for at least the errno values that I expect to come up in normal operation. Again, this can be dealt with by using a wrapper struct, but at the expense of at least some ergonomics -- right now what I have is a local conversion trait that lets me write

```rust
writeln!(stderr, "failed to {}: {}", operation, err.msg())

```

when `err` is an Errno, which is not bad but not as nice as

```rust
writeln!(stderr, "failed to {operation}: {err}")

```

---

_[View the full topic](https://internals.rust-lang.org/t/limited-opt-out-of-orphan-rule/21709)._
