# Use-ing only a trait not a derive with the same name

**URL:** <https://internals.rust-lang.org/t/use-ing-only-a-trait-not-a-derive-with-the-same-name/19153>\
**Category:** language design\
**Created:** [July 15, 2023, 4:14pm UTC](https://internals.rust-lang.org/t/use-ing-only-a-trait-not-a-derive-with-the-same-name/19153 "2023-07-15T16:14:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JelteF](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jeltef/32/2177_2.png) [@JelteF](https://internals.rust-lang.org/u/JelteF)\
**Post date:** [July 15, 2023, 4:14pm UTC](https://internals.rust-lang.org/t/use-ing-only-a-trait-not-a-derive-with-the-same-name/19153/1 "2023-07-15T16:14:32Z")

</div>

For my `derive_more` crate I'd like to `use` only the the `Debug` trait, but not the `Debug` derive. Because importing the derive would conflict with my own `Debug` derive that the trait creates. I cannot figure out a way to do this though, because this will always `use` both the trait and the derive:

```rust
pub use core::fmt::Debug

```

Is there any way to work around that? Or would this require language changes?

---

<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:** [July 15, 2023, 4:23pm UTC](https://internals.rust-lang.org/t/use-ing-only-a-trait-not-a-derive-with-the-same-name/19153/2 "2023-07-15T16:23:55Z")

</div>

> [@JelteF](#):
>
> Is there any way to work around that?

You could abuse the prioritization of explicit imports and items over glob imports. Example (this is the opposite of what you asked for, overriding the trait, just because that's easier to demonstrate).

```rust
// would be your derive macro crate
mod imp {
    pub trait Debug {}
}

mod namespace_gimmick {
    pub use std::fmt::*;
    pub use super::imp::Debug;
}
pub use namespace_gimmick::Debug as NewDebug;

// demonstrate that both were imported:
impl NewDebug for () {}
#[derive(NewDebug)]
struct Foo;

```

Since glob imports can be fragile, you'd want to do this in modules strictly dedicated to the purpose.

---

<div class="post-metadata">

**Author:** ![illicitonion](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/illicitonion/32/3886_2.png) [@illicitonion](https://internals.rust-lang.org/u/illicitonion)\
**Post date:** [July 15, 2023, 6:12pm UTC](https://internals.rust-lang.org/t/use-ing-only-a-trait-not-a-derive-with-the-same-name/19153/3 "2023-07-15T18:12:15Z")

</div>

You could rename it as you use it?

```rust
use core::fmt::Debug as _;

```

will bring the trait into scope but not name it.

```rust
use core::fmt::Debug as CoreDebug;

```

will bring it into scope with a different name.

---

<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:** [October 13, 2023, 6:12pm UTC](https://internals.rust-lang.org/t/use-ing-only-a-trait-not-a-derive-with-the-same-name/19153/4 "2023-10-13T18:12:47Z")

</div>

Closed on October 13, 2023, 6:12pm UTC

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