これができない。
struct Wrapper<T>(T);
impl<T, U> From<Wrapper<U>> for Wrapper<T>
where
T: From<U>,
{
fn from(p: Wrapper<U>) -> Wrapper<T> {
Wrapper(p.0.into())
}
}
fn main() {
let a = Wrapper::<i32>(42);
let _: Wrapper<f32> = a.into();
}
Compiling playground v0.0.1 (/playground)
error[E0119]: conflicting implementations of trait `std::convert::From<Wrapper<_>>` for type `Wrapper<_>`:
--> src/main.rs:3:1
|
3 | / impl<T, U> From<Wrapper<U>> for Wrapper<T>
4 | | where
5 | | T: From<U>,
6 | | {
... |
9 | | }
10 | | }
| |_^
|
= note: conflicting implementation in crate `core`:
- impl<T> std::convert::From<T> for T;
error: aborting due to previous error
For more information about this error, try `rustc --explain E0119`.
error: Could not compile `playground`.
To learn more, run the command again with --verbose.
おそらく同じ型同士のFrom(impl From<T> for T
)と衝突している。
Crieitは誰でも投稿できるサービスです。 是非記事の投稿をお願いします。どんな軽い内容でも投稿できます。
また、「こんな記事が読みたいけど見つからない!」という方は是非記事投稿リクエストボードへ!
こじんまりと作業ログやメモ、進捗を書き残しておきたい方はボード機能をご利用ください。
ボードとは?
コメント