{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/29693","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/29693/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/29693/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/29693/events","html_url":"https://github.com/rust-lang/rust/pull/29693","id":115740445,"number":29693,"title":"Implement FromIterator for arrays up to [T; 32]","user":{"login":"ollie27","id":7189418,"avatar_url":"https://avatars.githubusercontent.com/u/7189418?v=3","gravatar_id":"","url":"https://api.github.com/users/ollie27","html_url":"https://github.com/ollie27","followers_url":"https://api.github.com/users/ollie27/followers","following_url":"https://api.github.com/users/ollie27/following{/other_user}","gists_url":"https://api.github.com/users/ollie27/gists{/gist_id}","starred_url":"https://api.github.com/users/ollie27/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ollie27/subscriptions","organizations_url":"https://api.github.com/users/ollie27/orgs","repos_url":"https://api.github.com/users/ollie27/repos","events_url":"https://api.github.com/users/ollie27/events{/privacy}","received_events_url":"https://api.github.com/users/ollie27/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"brson","id":147214,"avatar_url":"https://avatars.githubusercontent.com/u/147214?v=3","gravatar_id":"","url":"https://api.github.com/users/brson","html_url":"https://github.com/brson","followers_url":"https://api.github.com/users/brson/followers","following_url":"https://api.github.com/users/brson/following{/other_user}","gists_url":"https://api.github.com/users/brson/gists{/gist_id}","starred_url":"https://api.github.com/users/brson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brson/subscriptions","organizations_url":"https://api.github.com/users/brson/orgs","repos_url":"https://api.github.com/users/brson/repos","events_url":"https://api.github.com/users/brson/events{/privacy}","received_events_url":"https://api.github.com/users/brson/received_events","type":"User","site_admin":false},"milestone":null,"comments":5,"created_at":"2015-11-08T15:49:17Z","updated_at":"2015-11-09T12:44:36Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/29693","html_url":"https://github.com/rust-lang/rust/pull/29693","diff_url":"https://github.com/rust-lang/rust/pull/29693.diff","patch_url":"https://github.com/rust-lang/rust/pull/29693.patch"},"body":"I have used basically the same macro as for `Default`.\r\nIt will `panic!` if the iterator is not exactly the correct length.\r\nThis goes some way to solving rust-lang/rfcs#1109.\r\n\r\nFor example:\r\n```rust\r\nfn from_iter<I: IntoIterator<Item=T>>(iterator: I) -> [T; 3] {\r\n    let mut i = iterator.into_iter();\r\n    let a = [\r\n        i.next().expect(\"iterator too short\"),\r\n        i.next().expect(\"iterator too short\"),\r\n        i.next().expect(\"iterator too short\"),\r\n    ];\r\n    assert!(i.next().is_none(), \"iterator too long\");\r\n    a\r\n}\r\n```\r\nThis relies on the evaluation order within array expressions which I don't know is well defined yet. If it's not it will be easy to fix.\r\nI have added some simple tests to `src/libcoretest/array.rs`.\r\n"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/155053455","html_url":"https://github.com/rust-lang/rust/pull/29693#issuecomment-155053455","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/29693","id":155053455,"user":{"login":"bluss","id":3209739,"avatar_url":"https://avatars.githubusercontent.com/u/3209739?v=3","gravatar_id":"","url":"https://api.github.com/users/bluss","html_url":"https://github.com/bluss","followers_url":"https://api.github.com/users/bluss/followers","following_url":"https://api.github.com/users/bluss/following{/other_user}","gists_url":"https://api.github.com/users/bluss/gists{/gist_id}","starred_url":"https://api.github.com/users/bluss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluss/subscriptions","organizations_url":"https://api.github.com/users/bluss/orgs","repos_url":"https://api.github.com/users/bluss/repos","events_url":"https://api.github.com/users/bluss/events{/privacy}","received_events_url":"https://api.github.com/users/bluss/received_events","type":"User","site_admin":false},"created_at":"2015-11-09T12:44:36Z","updated_at":"2015-11-09T12:44:36Z","body":"Yes it can, consider this:\r\n\r\n```rust\r\nlet mut r = (0..10);\r\nlet array: [i32; 5] = (&mut r).collect();\r\nassert_eq!(r.next(), 5);\r\n```\r\n\r\n`&mut I where I: Iterator` implements `Iterator`, so the “by value” argument to from_iter may be a mutable reference to an iterator."}}