{"action":"opened","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/39103","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/39103/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/39103/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/39103/events","html_url":"https://github.com/rust-lang/rust/issues/39103","id":201107868,"number":39103,"title":"Wrong example in the book for Borrow<_>","user":{"login":"gralpli","id":25158727,"avatar_url":"https://avatars.githubusercontent.com/u/25158727?v=3","gravatar_id":"","url":"https://api.github.com/users/gralpli","html_url":"https://github.com/gralpli","followers_url":"https://api.github.com/users/gralpli/followers","following_url":"https://api.github.com/users/gralpli/following{/other_user}","gists_url":"https://api.github.com/users/gralpli/gists{/gist_id}","starred_url":"https://api.github.com/users/gralpli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gralpli/subscriptions","organizations_url":"https://api.github.com/users/gralpli/orgs","repos_url":"https://api.github.com/users/gralpli/repos","events_url":"https://api.github.com/users/gralpli/events{/privacy}","received_events_url":"https://api.github.com/users/gralpli/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-01-16T20:04:53Z","updated_at":"2017-01-16T20:04:53Z","closed_at":null,"body":"Chapter _5.10. Borrow and AsRef_ contains the following example:\r\n\r\n```rust\r\nuse std::borrow::Borrow;\r\nuse std::fmt::Display;\r\n\r\nfn foo<T: Borrow<i32> + Display>(a: T) {\r\n    println!(\"a is borrowed: {}\", a);\r\n}\r\n\r\nlet mut i = 5;\r\n\r\nfoo(&i);\r\nfoo(&mut i);\r\n```\r\n\r\nI think this example is wrong, because the fact that ```a``` is ```Borrow<i32>``` is not used here. It also gives the impression that ```a``` needs to _be_ something borrowed, although it just needs to be something you can _borrow from_.\r\n\r\nI would suggest the following as a better example:\r\n\r\n```rust\r\nuse std::borrow::Borrow;\r\n\r\nfn foo<T: Borrow<i32>>(a: T) {\r\n    let b: &i32 = a.borrow();\r\n    println!(\"{}\", b);\r\n}\r\n\r\nlet mut four = 4;\r\n\r\nfoo(four);\r\nfoo(&four);\r\nfoo(&mut four);\r\n```"}}
{"actor":{"display_login":"gralpli"}}