1

I'm trying to understand the difference between the case where structs contain simple types vs. when they contain other structs. All guides/examples/... seem to use only basic types as fields and this works:

struct Something {
    some: i32,
    numbers: i32,
}

But this results in error:

struct Something {
    reader: Reader,
    writer: Writer,
}

On the current master: error: explicit lifetime bound required

So what's the solution here? Something is constructed with both reader and writer and is returned from that function - reader and writer themselves are not copied anywhere else.

viraptor
  • 33,322
  • 10
  • 107
  • 191

1 Answers1

2

Reader and Writer are traits and not other structs this is why that code does not work.

What you want to do does work with other structs as you can see here:

fn main() {
    #[deriving(Show)]
    struct OtherStruct {
        s: uint,
    }
    #[deriving(Show)]
    struct Something {
        reader: OtherStruct,
    }
    println!("{}" , Something { reader : OtherStruct { s : 10 } });
}

For the actual Reader that you want to use you can have a look here.

FlyingFoX
  • 3,379
  • 3
  • 32
  • 49