jonhoo / jonhoo/rust-for-rustaceans.com

Confusing example on covariance

Open
#48 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
CSS
Stars
171
Forks
29
PR merge metrics
No merged PRs in 30d

Description

I'm not sure if this is an issue or not, but I can't get my head round it.

I have a copy of the first printing, and on page 16, first paragraph we have a couple of sentences explaining that `&'a T` is covariant in `'a`, which I get. But then there is this sentence:

> `&'a T` is also covariant in `T`, so you can pass a `&Vec<&' static str>` to a function that takes `&Vec<'a str>`.

I think I know what the first bit means, but I don't understand how the example relates to it. It shows that `&Vec` is covariant in `T`, but that's not obviously the same thing.

Or is T here intended to be `Vec<&'a str>`? If so, we have two unrelated uses of `'a`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.