I am trying to implement my custom trait for both impl std::io::Read
and std::fs::DirEntry
- the idea is to implement trait both for directores as well as files, buffers and so on.
use std::fs::DirEntry;
use std::io::Read;
trait MyTrait {}
impl<T> MyTrait for T
where
T: Read,
{}
impl MyTrait for DirEntry {}
As a result I got error
error[E0119]: conflicting implementations of trait `MyTrait` for type `DirEntry`
--> src/mytrait.rs:11:1
|
6 | impl<T> MyTrait for T
| --------------------- first implementation here
...
11 | impl MyTrait for DirEntry {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `DirEntry`
|
= note: upstream crates may add a new impl of trait `std::io::Read` for type `std::fs::DirEntry` in future versions
For more information about this error, try `rustc --explain E0119`.
As far as I understand I cannot implement MyTrait
for both impl std::io::Read
and std::fs::DirEntry
because, somehow, std::fs::DirEntry
already implements std::io::Read
.
However I cannot find any information about this fact in the docs. I tried to find something in source code but my knowledge about Rust source code is none so mission failed.
I found the solution in which I should manually implement MyTrait
for std::fs::File
, buffers and so on with some helper macro (like impl_mytrait
) but I want to know where I can find informations about possible upstream implementations - and if it's possible I want to find better solution than impl_mytrait
macro.