{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments/183199859","pull_request_review_id":114162520,"id":183199859,"diff_hunk":"@@ -0,0 +1,908 @@\n+- Feature Name: (fill me in with a unique ident, my_awesome_feature)\n+- Start Date: 2018-04-04\n+- RFC PR: (leave this empty)\n+- Rust Issue: (leave this empty)\n+\n+# Summary\n+[summary]: #summary\n+\n+This RFC proposes to add futures to libcore, in order to support\n+the first-class `async`/`await` syntax proposed in a [companion RFC]. To start\n+with, we add the smallest fragment of the futures-rs library required, but we\n+anticipate follow-up RFCs ultimately bringing most of the library into libcore (to\n+provide a complete complement of APIs).\n+\n+The proposed APIs are based on the futures crate, but with two major changes:\n+\n+- The use of [pinned types] to enable borrowing within futures.\n+- Removing the associated `Error` type (and adjusting combinators accordingly),\n+  in favor of just using `Output = Result<T, E>` instead. The RFC includes an\n+  extension trait to provide conveniences for `Result`-producing futures as\n+  well.\n+\n+[pinned types]: https://github.com/rust-lang/rfcs/pull/2349\n+[companion RFC]: https://github.com/rust-lang/rfcs/pull/2394\n+\n+# Motivation\n+[motivation]: #motivation\n+\n+There are two reasons to consider bringing futures into the standard library.\n+\n+The first, and by far most important, is to provide a supporting mechanism for\n+`async`/`await` syntax:\n+\n+```rust\n+async fn function(argument: &str) -> usize {\n+     // ...\n+}\n+```\n+\n+The syntax itself is motivated in the [companion RFC]. As with closures, it\n+involves producing an anonymous type, so that the above declaration is\n+equivalent to:\n+\n+```rust\n+fn function<'a>(argument: &'a str) -> _Anonymous<'a, usize> {\n+     // ...\n+}\n+```\n+\n+and, again like a closure, the type is only usable through the trait it\n+implements: `Future`. Hence, to include this syntax in the language, we must\n+also introduce `Future` into `core` as a lang item.\n+\n+The second reason to introduce futures is to establish them more formally as\n+*the* way to express composable, asynchronous computation in Rust. Over time,\n+the futures library has been refined to a core that bakes in almost no\n+assumptions and is usable in a wide variety of contexts, including operating\n+systems and embedded devices. As such, it has also become a *de facto* standard\n+in this space, and there is a strong desire for the core parts of the library to\n+reach the same level of stability as `std` itself. Bringing futures into libcore\n+is a final step in standardization.\n+\n+## Changes from futures 0.2\n+\n+### Pinning\n+\n+The motivation to use the `Pin` is simple: it makes it possible for futures to\n+hold *internal borrows* across yield points, which allows for far more idiomatic\n+futures-based APIs. For example, an async `read` method currently has to take\n+*ownership* of both the I/O object and the buffer to read into, and then yield\n+ownership on success or failure:\n+\n+```rust\n+fn read<T: AsMut<[u8]>>(self, buf: T) ->\n+    impl Future<Item = (Self, T, usize), Error = (Self, T, io::Error)>\n+```\n+\n+This design is needed to ensure that the resulting future is `'static`, which is\n+in turn needed because borrowing across yield points isn't possible. It's very\n+unwieldy.\n+\n+Once we lift this restriction, however, we can write a signature that is\n+literally the `async` version of the usual `read`:\n+\n+```rust\n+async fn read(&mut self, buf: &mut [u8]) -> io::Result<usize>;","path":"text/0000-futures.md","position":86,"original_position":86,"commit_id":"1c4af67200b4e76086b654e4a35191286f284d1f","original_commit_id":"1c4af67200b4e76086b654e4a35191286f284d1f","user":{"login":"seanmonstar","id":51479,"avatar_url":"https://avatars1.githubusercontent.com/u/51479?v=4","gravatar_id":"","url":"https://api.github.com/users/seanmonstar","html_url":"https://github.com/seanmonstar","followers_url":"https://api.github.com/users/seanmonstar/followers","following_url":"https://api.github.com/users/seanmonstar/following{/other_user}","gists_url":"https://api.github.com/users/seanmonstar/gists{/gist_id}","starred_url":"https://api.github.com/users/seanmonstar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seanmonstar/subscriptions","organizations_url":"https://api.github.com/users/seanmonstar/orgs","repos_url":"https://api.github.com/users/seanmonstar/repos","events_url":"https://api.github.com/users/seanmonstar/events{/privacy}","received_events_url":"https://api.github.com/users/seanmonstar/received_events","type":"User","site_admin":false},"body":"Perhaps a more specific example can be included, one that cannot be implemented today? An async function returning a future that borrows both `self` and `buf` already is possible, [for example](https://play.rust-lang.org/?gist=7807e380c33c2b7a521c1ce7bf15ba20&version=beta) (beta just used for `impl Future`).","created_at":"2018-04-21T04:28:19Z","updated_at":"2018-04-21T04:28:19Z","html_url":"https://github.com/rust-lang/rfcs/pull/2395#discussion_r183199859","pull_request_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/2395","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments/183199859"},"html":{"href":"https://github.com/rust-lang/rfcs/pull/2395#discussion_r183199859"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/2395"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rfcs/pulls/2395","id":179993627,"html_url":"https://github.com/rust-lang/rfcs/pull/2395","diff_url":"https://github.com/rust-lang/rfcs/pull/2395.diff","patch_url":"https://github.com/rust-lang/rfcs/pull/2395.patch","issue_url":"https://api.github.com/repos/rust-lang/rfcs/issues/2395","number":2395,"state":"open","locked":false,"title":"RFC: add futures to libcore","user":{"login":"aturon","id":709807,"avatar_url":"https://avatars2.githubusercontent.com/u/709807?v=4","gravatar_id":"","url":"https://api.github.com/users/aturon","html_url":"https://github.com/aturon","followers_url":"https://api.github.com/users/aturon/followers","following_url":"https://api.github.com/users/aturon/following{/other_user}","gists_url":"https://api.github.com/users/aturon/gists{/gist_id}","starred_url":"https://api.github.com/users/aturon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aturon/subscriptions","organizations_url":"https://api.github.com/users/aturon/orgs","repos_url":"https://api.github.com/users/aturon/repos","events_url":"https://api.github.com/users/aturon/events{/privacy}","received_events_url":"https://api.github.com/users/aturon/received_events","type":"User","site_admin":false},"body":"This RFC proposes to add futures to libcore, in order to support the first-class `async`/`await` syntax proposed in a [companion RFC]. To start with, we add the smallest fragment of the futures-rs library required, but we anticipate follow-up RFCs ultimately bringing most of the library into libcore (to provide a complete complement of APIs).\r\n\r\nThe proposed APIs are based on the futures crate, but with two major changes:\r\n\r\n- The use of [pinned types] to enable borrowing within futures.\r\n- Removing the associated `Error` type (and adjusting combinators accordingly), in favor of just using `Item = Result<T, E>` instead. The RFC includes an extension trait to provide conveniences for `Result`-producing futures as well.\r\n\r\n[pinned types]: https://github.com/rust-lang/rfcs/pull/2349\r\n[companion RFC]: https://github.com/rust-lang/rfcs/pull/2394\r\n\r\n[Rendered](https://github.com/aturon/rfcs/blob/futures/text/0000-futures.md)","created_at":"2018-04-06T16:18:28Z","updated_at":"2018-04-21T04:28:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"79d5cba3b0d1ae597a92d7182bc992cfa6cc8e1a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":211667901,"url":"https://api.github.com/repos/rust-lang/rfcs/labels/T-libs","name":"T-libs","color":"bfd4f2","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/2395/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/2395/comments","review_comment_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/issues/2395/comments","statuses_url":"https://api.github.com/repos/rust-lang/rfcs/statuses/1c4af67200b4e76086b654e4a35191286f284d1f","head":{"label":"aturon:futures","ref":"futures","sha":"1c4af67200b4e76086b654e4a35191286f284d1f","user":{"login":"aturon","id":709807,"avatar_url":"https://avatars2.githubusercontent.com/u/709807?v=4","gravatar_id":"","url":"https://api.github.com/users/aturon","html_url":"https://github.com/aturon","followers_url":"https://api.github.com/users/aturon/followers","following_url":"https://api.github.com/users/aturon/following{/other_user}","gists_url":"https://api.github.com/users/aturon/gists{/gist_id}","starred_url":"https://api.github.com/users/aturon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aturon/subscriptions","organizations_url":"https://api.github.com/users/aturon/orgs","repos_url":"https://api.github.com/users/aturon/repos","events_url":"https://api.github.com/users/aturon/events{/privacy}","received_events_url":"https://api.github.com/users/aturon/received_events","type":"User","site_admin":false},"repo":{"id":20423396,"name":"rfcs","full_name":"aturon/rfcs","owner":{"login":"aturon","id":709807,"avatar_url":"https://avatars2.githubusercontent.com/u/709807?v=4","gravatar_id":"","url":"https://api.github.com/users/aturon","html_url":"https://github.com/aturon","followers_url":"https://api.github.com/users/aturon/followers","following_url":"https://api.github.com/users/aturon/following{/other_user}","gists_url":"https://api.github.com/users/aturon/gists{/gist_id}","starred_url":"https://api.github.com/users/aturon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aturon/subscriptions","organizations_url":"https://api.github.com/users/aturon/orgs","repos_url":"https://api.github.com/users/aturon/repos","events_url":"https://api.github.com/users/aturon/events{/privacy}","received_events_url":"https://api.github.com/users/aturon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/aturon/rfcs","description":"RFCs for changes to Rust","fork":true,"url":"https://api.github.com/repos/aturon/rfcs","forks_url":"https://api.github.com/repos/aturon/rfcs/forks","keys_url":"https://api.github.com/repos/aturon/rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aturon/rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aturon/rfcs/teams","hooks_url":"https://api.github.com/repos/aturon/rfcs/hooks","issue_events_url":"https://api.github.com/repos/aturon/rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/aturon/rfcs/events","assignees_url":"https://api.github.com/repos/aturon/rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/aturon/rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/aturon/rfcs/tags","blobs_url":"https://api.github.com/repos/aturon/rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aturon/rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aturon/rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/aturon/rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aturon/rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/aturon/rfcs/languages","stargazers_url":"https://api.github.com/repos/aturon/rfcs/stargazers","contributors_url":"https://api.github.com/repos/aturon/rfcs/contributors","subscribers_url":"https://api.github.com/repos/aturon/rfcs/subscribers","subscription_url":"https://api.github.com/repos/aturon/rfcs/subscription","commits_url":"https://api.github.com/repos/aturon/rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/aturon/rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/aturon/rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/aturon/rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/aturon/rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/aturon/rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aturon/rfcs/merges","archive_url":"https://api.github.com/repos/aturon/rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aturon/rfcs/downloads","issues_url":"https://api.github.com/repos/aturon/rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/aturon/rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/aturon/rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/aturon/rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aturon/rfcs/labels{/name}","releases_url":"https://api.github.com/repos/aturon/rfcs/releases{/id}","deployments_url":"https://api.github.com/repos/aturon/rfcs/deployments","created_at":"2014-06-02T23:35:56Z","updated_at":"2018-02-26T01:33:21Z","pushed_at":"2018-04-21T00:48:53Z","git_url":"git://github.com/aturon/rfcs.git","ssh_url":"git@github.com:aturon/rfcs.git","clone_url":"https://github.com/aturon/rfcs.git","svn_url":"https://github.com/aturon/rfcs","homepage":"","size":5546,"stargazers_count":59,"watchers_count":59,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":18,"open_issues":0,"watchers":59,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"8bffc2fc5c0d6b25d101af69f18b9df9da7b134b","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars1.githubusercontent.com/u/5430905?v=4","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":17527989,"name":"rfcs","full_name":"rust-lang/rfcs","owner":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars1.githubusercontent.com/u/5430905?v=4","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rust-lang/rfcs","description":"RFCs for changes to Rust","fork":false,"url":"https://api.github.com/repos/rust-lang/rfcs","forks_url":"https://api.github.com/repos/rust-lang/rfcs/forks","keys_url":"https://api.github.com/repos/rust-lang/rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/rfcs/teams","hooks_url":"https://api.github.com/repos/rust-lang/rfcs/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/rfcs/events","assignees_url":"https://api.github.com/repos/rust-lang/rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/rfcs/tags","blobs_url":"https://api.github.com/repos/rust-lang/rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/rfcs/languages","stargazers_url":"https://api.github.com/repos/rust-lang/rfcs/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/rfcs/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/rfcs/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/rfcs/subscription","commits_url":"https://api.github.com/repos/rust-lang/rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang/rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/rfcs/merges","archive_url":"https://api.github.com/repos/rust-lang/rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/rfcs/downloads","issues_url":"https://api.github.com/repos/rust-lang/rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/rfcs/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/rfcs/releases{/id}","deployments_url":"https://api.github.com/repos/rust-lang/rfcs/deployments","created_at":"2014-03-07T21:29:00Z","updated_at":"2018-04-20T22:01:01Z","pushed_at":"2018-04-21T00:48:56Z","git_url":"git://github.com/rust-lang/rfcs.git","ssh_url":"git@github.com:rust-lang/rfcs.git","clone_url":"https://github.com/rust-lang/rfcs.git","svn_url":"https://github.com/rust-lang/rfcs","homepage":"http://rust-lang.github.io/rfcs/","size":94417,"stargazers_count":1454,"watchers_count":1454,"language":"Shell","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":604,"mirror_url":null,"archived":false,"open_issues_count":719,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":604,"open_issues":719,"watchers":1454,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/2395"},"html":{"href":"https://github.com/rust-lang/rfcs/pull/2395"},"issue":{"href":"https://api.github.com/repos/rust-lang/rfcs/issues/2395"},"comments":{"href":"https://api.github.com/repos/rust-lang/rfcs/issues/2395/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/2395/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/2395/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rfcs/statuses/1c4af67200b4e76086b654e4a35191286f284d1f"}},"author_association":"OWNER"}}
{"actor":{"display_login":"seanmonstar"}}