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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.