{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/comments/26864289","id":26864289,"diff_hunk":"@@ -0,0 +1,146 @@\n+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT\n+// file at the top-level directory of this distribution and at\n+// http://rust-lang.org/COPYRIGHT.\n+//\n+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or\n+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your\n+// option. This file may not be copied, modified, or distributed\n+// except according to those terms.\n+\n+//! Traits for conversions between types.\n+//!\n+//! The traits in this module provide a general way to talk about\n+//! conversions from one type to another. They follow the standard\n+//! Rust conventions of `as`/`to`/`into`/`from`.\n+\n+#![unstable(feature = \"convert\",\n+            reason = \"recently added, experimental traits\")]\n+\n+use option::Option;\n+use result::Result;\n+use marker::Sized;\n+\n+/// A cheap, reference-to-reference conversion.\n+pub trait As<T: ?Sized> {\n+    /// Perform the conversion.\n+    fn convert_as(&self) -> &T;\n+}\n+\n+/// A cheap, mutable reference-to-mutable reference conversion.\n+pub trait AsMut<T: ?Sized> {\n+    /// Perform the conversion.\n+    fn convert_as_mut(&mut self) -> &mut T;\n+}\n+\n+/// A possibly expensive conversion from a reference.\n+pub trait To<T> {\n+    /// Perform the conversion.\n+    fn convert_to(&self) -> T;\n+}\n+\n+/// A conversion that consumes `self`, which may or may not be\n+/// expensive.\n+pub trait Into<T>: Sized {\n+    /// Perform the conversion.\n+    fn convert_into(self) -> T;\n+}\n+\n+/// Construct `Self` via a conversion.\n+pub trait From<T> {\n+    /// Perform the conversion.\n+    fn from(T) -> Self;\n+}\n+\n+////////////////////////////////////////////////////////////////////////////////\n+// GENERIC IMPLS\n+////////////////////////////////////////////////////////////////////////////////\n+\n+// As implies To\n+impl<'a, T: ?Sized, U: ?Sized> To<&'a U> for &'a T where T: As<U> {\n+    fn convert_to(&self) -> &'a U {\n+        (*self).convert_as()\n+    }\n+}\n+\n+// As lifts over &\n+impl<'a, T: ?Sized, U: ?Sized> As<U> for &'a T where T: As<U> {\n+    fn convert_as(&self) -> &U {\n+        <T as As<U>>::convert_as(*self)\n+    }\n+}\n+\n+// As lifts over &mut\n+impl<'a, T: ?Sized, U: ?Sized> As<U> for &'a mut T where T: As<U> {\n+    fn convert_as(&self) -> &U {\n+        <T as As<U>>::convert_as(*self)\n+    }\n+}\n+\n+// AsMut implies Into\n+impl<'a, T: ?Sized, U: ?Sized> Into<&'a mut U> for &'a mut T where T: AsMut<U> {\n+    fn convert_into(self) -> &'a mut U {\n+        (*self).convert_as_mut()\n+    }\n+}\n+\n+// AsMut lifts over &mut\n+impl<'a, T: ?Sized, U: ?Sized> AsMut<U> for &'a mut T where T: AsMut<U> {\n+    fn convert_as_mut(&mut self) -> &mut U {\n+        (*self).convert_as_mut()\n+    }\n+}\n+\n+// To implies Into\n+impl<'a, T: ?Sized, U> Into<U> for &'a T where T: To<U> {\n+    fn convert_into(self) -> U {\n+        self.convert_to()\n+    }\n+}\n+\n+// Into implies From\n+impl<T, U> From<T> for U where T: Into<U> {\n+    fn from(t: T) -> U {\n+        t.convert_into()\n+    }\n+}\n+\n+////////////////////////////////////////////////////////////////////////////////\n+// CONCRETE IMPLS\n+////////////////////////////////////////////////////////////////////////////////\n+\n+impl<T> As<[T]> for [T] {\n+    fn convert_as(&self) -> &[T] {\n+        self\n+    }\n+}\n+\n+impl<T> AsMut<[T]> for [T] {\n+    fn convert_as_mut(&mut self) -> &mut [T] {\n+        self\n+    }\n+}\n+\n+impl As<str> for str {\n+    fn convert_as(&self) -> &str {\n+        self\n+    }\n+}\n+\n+impl<T> As<[T]> for Option<T> {\n+    fn convert_as(&self) -> &[T] {\n+        self.as_slice()\n+    }\n+}","path":"src/libcore/convert.rs","position":134,"original_position":134,"commit_id":"3c62067f27a06178ce9acabbaf1855545121a7ed","original_commit_id":"3c62067f27a06178ce9acabbaf1855545121a7ed","user":{"login":"aturon","id":709807,"avatar_url":"https://avatars.githubusercontent.com/u/709807?v=3","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":"I'm willing to mark this unstable, but personally I have no objection to this functionality, *especially* in the context of generic conversions.","created_at":"2015-03-20T18:30:12Z","updated_at":"2015-03-20T18:30:12Z","html_url":"https://github.com/rust-lang/rust/pull/23538#discussion_r26864289","pull_request_url":"https://api.github.com/repos/rust-lang/rust/pulls/23538","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments/26864289"},"html":{"href":"https://github.com/rust-lang/rust/pull/23538#discussion_r26864289"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/23538"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/23538","id":31578772,"html_url":"https://github.com/rust-lang/rust/pull/23538","diff_url":"https://github.com/rust-lang/rust/pull/23538.diff","patch_url":"https://github.com/rust-lang/rust/pull/23538.patch","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/23538","number":23538,"state":"open","locked":false,"title":"[WIP] Add generic conversion traits","user":{"login":"aturon","id":709807,"avatar_url":"https://avatars.githubusercontent.com/u/709807?v=3","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 commit:\r\n\r\n* Introduces `std::convert`, providing an implementation of\r\nRFC 529.\r\n\r\n* Deprecates the `AsPath`, `AsOsStr`, and `IntoBytes` traits, all\r\nin favor of the corresponding generic conversion traits.\r\n\r\n  Consequently, various IO APIs now take `As<Path>` rather than\r\n`AsPath`, and so on. Since the types provided by `std` implement both\r\ntraits, this should cause relatively little breakage.\r\n\r\n* Deprecates many `from_foo` constructors in favor of `from`.\r\n\r\n* Changes `PathBuf::new` to take no argument (creating an empty buffer,\r\n  as per convention). The previous behavior is now available as\r\n  `PathBuf::from`.\r\n\r\n* De-stabilizes `IntoCow`. It's not clear whether we need this separate trait.\r\n\r\nCloses #22751\r\n\r\n[breaking-change]\r\n\r\nr? @alexcrichton \r\ncc @Gankro @erickt @cmr","created_at":"2015-03-20T00:17:23Z","updated_at":"2015-03-20T18:30:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7c2c952763afe89c473a362bdace3af63d388815","assignee":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rust/pulls/23538/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rust/pulls/23538/comments","review_comment_url":"https://api.github.com/repos/rust-lang/rust/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/23538/comments","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/3c62067f27a06178ce9acabbaf1855545121a7ed","head":{"label":"aturon:conversion","ref":"conversion","sha":"3c62067f27a06178ce9acabbaf1855545121a7ed","user":{"login":"aturon","id":709807,"avatar_url":"https://avatars.githubusercontent.com/u/709807?v=3","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":19056749,"name":"rust","full_name":"aturon/rust","owner":{"login":"aturon","id":709807,"avatar_url":"https://avatars.githubusercontent.com/u/709807?v=3","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/rust","description":"a safe, concurrent, practical language","fork":true,"url":"https://api.github.com/repos/aturon/rust","forks_url":"https://api.github.com/repos/aturon/rust/forks","keys_url":"https://api.github.com/repos/aturon/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aturon/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aturon/rust/teams","hooks_url":"https://api.github.com/repos/aturon/rust/hooks","issue_events_url":"https://api.github.com/repos/aturon/rust/issues/events{/number}","events_url":"https://api.github.com/repos/aturon/rust/events","assignees_url":"https://api.github.com/repos/aturon/rust/assignees{/user}","branches_url":"https://api.github.com/repos/aturon/rust/branches{/branch}","tags_url":"https://api.github.com/repos/aturon/rust/tags","blobs_url":"https://api.github.com/repos/aturon/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aturon/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aturon/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/aturon/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aturon/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/aturon/rust/languages","stargazers_url":"https://api.github.com/repos/aturon/rust/stargazers","contributors_url":"https://api.github.com/repos/aturon/rust/contributors","subscribers_url":"https://api.github.com/repos/aturon/rust/subscribers","subscription_url":"https://api.github.com/repos/aturon/rust/subscription","commits_url":"https://api.github.com/repos/aturon/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/aturon/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/aturon/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/aturon/rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/aturon/rust/contents/{+path}","compare_url":"https://api.github.com/repos/aturon/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aturon/rust/merges","archive_url":"https://api.github.com/repos/aturon/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aturon/rust/downloads","issues_url":"https://api.github.com/repos/aturon/rust/issues{/number}","pulls_url":"https://api.github.com/repos/aturon/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/aturon/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/aturon/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aturon/rust/labels{/name}","releases_url":"https://api.github.com/repos/aturon/rust/releases{/id}","created_at":"2014-04-23T04:19:14Z","updated_at":"2014-06-21T05:46:22Z","pushed_at":"2015-03-20T17:46:41Z","git_url":"git://github.com/aturon/rust.git","ssh_url":"git@github.com:aturon/rust.git","clone_url":"https://github.com/aturon/rust.git","svn_url":"https://github.com/aturon/rust","homepage":"http://www.rust-lang.org","size":254618,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"e98e391337fdbf32607de4889345c13fed9de21b","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","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":724712,"name":"rust","full_name":"rust-lang/rust","owner":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","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/rust","description":"a safe, concurrent, practical language","fork":false,"url":"https://api.github.com/repos/rust-lang/rust","forks_url":"https://api.github.com/repos/rust-lang/rust/forks","keys_url":"https://api.github.com/repos/rust-lang/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/rust/teams","hooks_url":"https://api.github.com/repos/rust-lang/rust/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/rust/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/rust/events","assignees_url":"https://api.github.com/repos/rust-lang/rust/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/rust/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/rust/tags","blobs_url":"https://api.github.com/repos/rust-lang/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/rust/languages","stargazers_url":"https://api.github.com/repos/rust-lang/rust/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/rust/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/rust/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/rust/subscription","commits_url":"https://api.github.com/repos/rust-lang/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang/rust/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/rust/merges","archive_url":"https://api.github.com/repos/rust-lang/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/rust/downloads","issues_url":"https://api.github.com/repos/rust-lang/rust/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/rust/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/rust/releases{/id}","created_at":"2010-06-16T20:39:03Z","updated_at":"2015-03-20T17:39:45Z","pushed_at":"2015-03-20T17:56:50Z","git_url":"git://github.com/rust-lang/rust.git","ssh_url":"git@github.com:rust-lang/rust.git","clone_url":"https://github.com/rust-lang/rust.git","svn_url":"https://github.com/rust-lang/rust","homepage":"http://www.rust-lang.org","size":511719,"stargazers_count":9781,"watchers_count":9781,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1902,"mirror_url":null,"open_issues_count":2058,"forks":1902,"open_issues":2058,"watchers":9781,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/23538"},"html":{"href":"https://github.com/rust-lang/rust/pull/23538"},"issue":{"href":"https://api.github.com/repos/rust-lang/rust/issues/23538"},"comments":{"href":"https://api.github.com/repos/rust-lang/rust/issues/23538/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/23538/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/23538/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rust/statuses/3c62067f27a06178ce9acabbaf1855545121a7ed"}}}}