Hi all,
I'm implementing this:
pub enum OwnBorrow<T: 'static> {
Owned(T),
Borrowed(&'static T),
}
impl<T> OwnBorrow<T> {
pub fn owned(val: T) -> OwnBorrow<T> { OwnBorrow::Owned(val) }
pub fn borrowed(val: &'static T) -> OwnBorrow<T> { OwnBorrow::Borrowed(val) }
fn reference(&self) -> &T {
match self {
&OwnBorrow::Owned(ref v) => v,
&OwnBorrow::Borrowed(v) => v,
}
}
}
impl<T: Clone> Into<T> for OwnBorrow<T> {
fn into(self) -> T {
match self {
&OwnBorrow::Owned(v) => v,
&OwnBorrow::Borrowed(v) => v.clone(),
}
}
}
//...
However the compiler (nightly, a few days old) complains:
src/ownborrow.rs:26:1: 33:2 error: conflicting implementations for trait
core::convert::Into
[E0119]
src/ownborrow.rs:26 impl<T: Clone> Into for OwnBorrow {
src/ownborrow.rs:27 fn into(self) -> T {
src/ownborrow.rs:28 match self {
src/ownborrow.rs:29 &OwnBorrow::Owned(v) => v,
src/ownborrow.rs:30 &OwnBorrow::Borrowed(v) => v.clone(),
src/ownborrow.rs:31 }
...
src/ownborrow.rs:26:1: 33:2 help: runrustc --explain E0119
to see a detailed explanation
src/ownborrow.rs:26:1: 33:2 note: conflicting implementation in cratecore
src/ownborrow.rs:26 impl<T: Clone> Into for OwnBorrow {
src/ownborrow.rs:27 fn into(self) -> T {
src/ownborrow.rs:28 match self {
src/ownborrow.rs:29 &OwnBorrow::Owned(v) => v,
src/ownborrow.rs:30 &OwnBorrow::Borrowed(v) => v.clone(),
src/ownborrow.rs:31 }
...
error: aborting due to previous error
However, I can't see how its already implemented, and I can't see any clue in this message. The only possible candidate I can see is:
impl<T, U> Into<U> for T where U: From<T>
but I'm not implementing From.
Clues?
Also, this seems like a type which should already exist, but I couldn't find it. Is that because it won't actually work? I'm concerned about the &T
lifetime, and not really sure if 'static
will work.
Thanks, J