The ~int type has since moved to Box<int>, which will one day be a
library type with Deref implemented on it (currently it is implemented
by the compiler). Regardless, there's no need to implement the Deref
trait for the type today, the compiler already takes care of it.

For example, your code will compile without the deref trait:

fn main() {
    let x: Box<int> = box 3;
    let y = *x;
    println!("{}", y);
}

The language only allows for one definition of each lang item, and
most lang items now reside in libcore, so you shouldn't have to define
them manually.

On Mon, May 12, 2014 at 11:50 AM, Noah Watkins <jayh...@cs.ucsc.edu> wrote:
> I am trying to capture the reference to type `~int` with the following
> code. I can change it to apply to bare `int` and it works fine.
>
> #[lang="deref"]
> pub trait Deref<Result> {
>     fn deref<'a>(&'a self) -> &'a Result;
> }
>
> impl Deref<~int> for ~int {
>     fn deref<'a>(&'a self) -> &'a ~int {
>         println!("deref caught");
>         self
>     }
> }
>
> fn main() {
>   let x: ~int = 3;
>   *x
> }
>
> Thanks,
> Noah
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to