Skip to content

Instantly share code, notes, and snippets.

@erickt
Last active October 16, 2015 03:38
Show Gist options
  • Save erickt/aae745395d049eb0f8b8 to your computer and use it in GitHub Desktop.
Save erickt/aae745395d049eb0f8b8 to your computer and use it in GitHub Desktop.
multirust run nightly rustc --crate-type lib bar.rs && multirust run nightly rustc -L . foo.rs
pub trait MyFrom2<T> {
fn my_from2(T) -> Self;
}
extern crate bar;
use std::convert::From;
use bar::MyFrom2;
struct MyVec(Vec<u8>);
impl<'a> From<&'a [u8]> for MyVec {
fn from(s: &[u8]) -> MyVec {
MyVec(s.to_owned())
}
}
trait MyFrom<T> {
fn my_from(T) -> Self;
}
impl<'a> MyFrom<&'a [u8]> for MyVec {
fn my_from(s: &[u8]) -> MyVec {
MyVec(s.to_owned())
}
}
impl<'a> MyFrom2<&'a [u8]> for MyVec {
fn my_from2(s: &[u8]) -> MyVec {
MyVec(s.to_owned())
}
}
fn make(s: &[u8]) -> MyVec {
MyVec(s.to_owned())
}
fn main() {
let _v = MyVec::from(&b"123"[..]);
// let _v = MyVec::from(b"123");
//
// Error's with:
// foo.rs:27:14: 27:25 error: the trait `core::convert::From<&[u8; 3]>` is not implemented for the type `MyVec` [E0277]
// foo.rs:27 let _v = MyVec::from(b"123");
// ^~~~~~~~~~~
let _v = MyVec::my_from(&b"123"[..]);
let _v = MyVec::my_from(b"123");
let _v = MyVec::my_from2(&b"123"[..]);
let _v = MyVec::my_from2(b"123");
let _v = make(b"123");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment