{"action":"created","comment":{"url":"https://api.github.com/repos/danburkert/procinfo-rs/pulls/comments/135421766","pull_request_review_id":58832151,"id":135421766,"diff_hunk":"@@ -8,59 +8,148 @@ use std::path::Path;\n use std::iter::Iterator;\n \n use libc::pid_t;\n-use nom::IResult;\n+use nom::{self, IResult};\n \n+/// An environment holder.\n #[derive(Debug, Clone)]\n pub struct Environ {\n     data: Vec<u8>,\n }\n \n-impl Environ {\n-    fn parse(&self) -> Option<Result<(Vec<u8>, (OsString, OsString))>> {\n-        if self.data.is_empty() {\n-            // Don't attempt to parse an empty file.\n-            return None;\n-        }\n-        // Map the result of `take_until_and_consume` to OsString.\n-        named_args!(\n-            until<'a>(sep: &'a str)<OsString>,\n-            map!(take_until_and_consume!(sep), from_bytes)\n-        );\n-        // Parse 'key=value\" pair.\n-        named!(\n-            pair<&[u8], (OsString, OsString)>,\n-            tuple!(apply!(until, \"=\"), apply!(until, \"\\0\"))\n-        );\n-        match pair(&self.data) {\n-            IResult::Done(leftover, parsed) => Some(Ok((leftover.to_vec(), parsed))),\n+/// An iterator over environment variables.\n+pub struct EnvironIter<'a> {\n+    environ: &'a Environ,\n+    leftover: &'a [u8],\n+}\n+\n+impl<'a> EnvironIter<'a> {\n+    fn parse(&self) -> Option<Result<(&'a [u8], (OsString, OsString))>> {\n+        match pair(self.leftover) {\n+            IResult::Done(leftover, parsed) => Some(Ok((leftover, parsed))),\n             IResult::Incomplete(_) => None,\n             IResult::Error(err) => Some(Err(Error::new(\n                 ErrorKind::InvalidInput,\n-                format!(\"unable to parse input: {:?}\", err),\n+                format!(\"Unable to parse input: {:?}\", err),\n             ))),\n         }\n     }\n }\n \n-impl Iterator for Environ {\n+impl<'a> Iterator for EnvironIter<'a> {\n     type Item = Result<(OsString, OsString)>;\n \n     fn next(&mut self) -> Option<Self::Item> {\n-        self.parse().map(|res| {\n-            res.map(|(leftover, pair)| {\n-                self.data = leftover;\n-                pair\n-            })\n-        })\n+        if self.leftover.len() == 0 {\n+            return None;\n+        }\n+        let (leftover, item) = match self.parse() {\n+            None => return None,\n+            Some(Err(x)) => return Some(Err(x)),\n+            Some(Ok(x)) => x,\n+        };\n+        self.leftover = leftover;\n+        Some(Ok(item))\n+    }\n+}\n+\n+impl<'a> IntoIterator for &'a Environ {\n+    type Item = Result<(OsString, OsString)>;\n+    type IntoIter = EnvironIter<'a>;\n+\n+    fn into_iter(self) -> Self::IntoIter {\n+        EnvironIter {\n+            environ: self,\n+            leftover: &self.data,\n+        }\n     }\n }\n \n+/// Extracts name of a variable. Also consumes a delimiter.\n+fn get_name(src: &[u8]) -> IResult<&[u8], OsString> {\n+    // Calculate position of the equal sign.\n+    let pos = match src.iter().skip(1).position(|c| c == &b'=') {\n+        Some(p) => p,\n+        None => return IResult::Error(error_position!(nom::ErrorKind::Custom(0), src)),","path":"src/pid/environ.rs","position":72,"original_position":92,"commit_id":"7fc92bb8ccc5c7c7a9c219a4d4b1f93f43e3c9e8","original_commit_id":"7fc92bb8ccc5c7c7a9c219a4d4b1f93f43e3c9e8","user":{"login":"mexus","id":3609357,"avatar_url":"https://avatars0.githubusercontent.com/u/3609357?v=4","gravatar_id":"","url":"https://api.github.com/users/mexus","html_url":"https://github.com/mexus","followers_url":"https://api.github.com/users/mexus/followers","following_url":"https://api.github.com/users/mexus/following{/other_user}","gists_url":"https://api.github.com/users/mexus/gists{/gist_id}","starred_url":"https://api.github.com/users/mexus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mexus/subscriptions","organizations_url":"https://api.github.com/users/mexus/orgs","repos_url":"https://api.github.com/users/mexus/repos","events_url":"https://api.github.com/users/mexus/events{/privacy}","received_events_url":"https://api.github.com/users/mexus/received_events","type":"User","site_admin":false},"body":"This is a fishy part, not sure which error to return.","created_at":"2017-08-27T21:29:46Z","updated_at":"2017-08-27T21:31:14Z","html_url":"https://github.com/danburkert/procinfo-rs/pull/28#discussion_r135421766","pull_request_url":"https://api.github.com/repos/danburkert/procinfo-rs/pulls/28","_links":{"self":{"href":"https://api.github.com/repos/danburkert/procinfo-rs/pulls/comments/135421766"},"html":{"href":"https://github.com/danburkert/procinfo-rs/pull/28#discussion_r135421766"},"pull_request":{"href":"https://api.github.com/repos/danburkert/procinfo-rs/pulls/28"}}},"pull_request":{"url":"https://api.github.com/repos/danburkert/procinfo-rs/pulls/28","id":137813779,"html_url":"https://github.com/danburkert/procinfo-rs/pull/28","diff_url":"https://github.com/danburkert/procinfo-rs/pull/28.diff","patch_url":"https://github.com/danburkert/procinfo-rs/pull/28.patch","issue_url":"https://api.github.com/repos/danburkert/procinfo-rs/issues/28","number":28,"state":"open","locked":false,"title":"Added parser for `/proc/[pid]/environ`","user":{"login":"mexus","id":3609357,"avatar_url":"https://avatars0.githubusercontent.com/u/3609357?v=4","gravatar_id":"","url":"https://api.github.com/users/mexus","html_url":"https://github.com/mexus","followers_url":"https://api.github.com/users/mexus/followers","following_url":"https://api.github.com/users/mexus/following{/other_user}","gists_url":"https://api.github.com/users/mexus/gists{/gist_id}","starred_url":"https://api.github.com/users/mexus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mexus/subscriptions","organizations_url":"https://api.github.com/users/mexus/orgs","repos_url":"https://api.github.com/users/mexus/repos","events_url":"https://api.github.com/users/mexus/events{/privacy}","received_events_url":"https://api.github.com/users/mexus/received_events","type":"User","site_admin":false},"body":"Hi!\r\n\r\nFirst of all, thanks for a great and simple library!\r\nI though it'd be nice to contribute to the project so I found out that there is no parser for a `/proc/[pid]/environ` file and implemented it :)\r\n\r\nPlease consider to review & merge if it's okay.","created_at":"2017-08-26T22:11:51Z","updated_at":"2017-08-27T21:31:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e35b825aae91f8d06ea6766b0798b537640c3030","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/danburkert/procinfo-rs/pulls/28/commits","review_comments_url":"https://api.github.com/repos/danburkert/procinfo-rs/pulls/28/comments","review_comment_url":"https://api.github.com/repos/danburkert/procinfo-rs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/danburkert/procinfo-rs/issues/28/comments","statuses_url":"https://api.github.com/repos/danburkert/procinfo-rs/statuses/7fc92bb8ccc5c7c7a9c219a4d4b1f93f43e3c9e8","head":{"label":"mexus:master","ref":"master","sha":"7fc92bb8ccc5c7c7a9c219a4d4b1f93f43e3c9e8","user":{"login":"mexus","id":3609357,"avatar_url":"https://avatars0.githubusercontent.com/u/3609357?v=4","gravatar_id":"","url":"https://api.github.com/users/mexus","html_url":"https://github.com/mexus","followers_url":"https://api.github.com/users/mexus/followers","following_url":"https://api.github.com/users/mexus/following{/other_user}","gists_url":"https://api.github.com/users/mexus/gists{/gist_id}","starred_url":"https://api.github.com/users/mexus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mexus/subscriptions","organizations_url":"https://api.github.com/users/mexus/orgs","repos_url":"https://api.github.com/users/mexus/repos","events_url":"https://api.github.com/users/mexus/events{/privacy}","received_events_url":"https://api.github.com/users/mexus/received_events","type":"User","site_admin":false},"repo":{"id":101449471,"name":"procinfo-rs","full_name":"mexus/procinfo-rs","owner":{"login":"mexus","id":3609357,"avatar_url":"https://avatars0.githubusercontent.com/u/3609357?v=4","gravatar_id":"","url":"https://api.github.com/users/mexus","html_url":"https://github.com/mexus","followers_url":"https://api.github.com/users/mexus/followers","following_url":"https://api.github.com/users/mexus/following{/other_user}","gists_url":"https://api.github.com/users/mexus/gists{/gist_id}","starred_url":"https://api.github.com/users/mexus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mexus/subscriptions","organizations_url":"https://api.github.com/users/mexus/orgs","repos_url":"https://api.github.com/users/mexus/repos","events_url":"https://api.github.com/users/mexus/events{/privacy}","received_events_url":"https://api.github.com/users/mexus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mexus/procinfo-rs","description":"A Rust library for accessing Linux process and system information","fork":true,"url":"https://api.github.com/repos/mexus/procinfo-rs","forks_url":"https://api.github.com/repos/mexus/procinfo-rs/forks","keys_url":"https://api.github.com/repos/mexus/procinfo-rs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mexus/procinfo-rs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mexus/procinfo-rs/teams","hooks_url":"https://api.github.com/repos/mexus/procinfo-rs/hooks","issue_events_url":"https://api.github.com/repos/mexus/procinfo-rs/issues/events{/number}","events_url":"https://api.github.com/repos/mexus/procinfo-rs/events","assignees_url":"https://api.github.com/repos/mexus/procinfo-rs/assignees{/user}","branches_url":"https://api.github.com/repos/mexus/procinfo-rs/branches{/branch}","tags_url":"https://api.github.com/repos/mexus/procinfo-rs/tags","blobs_url":"https://api.github.com/repos/mexus/procinfo-rs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mexus/procinfo-rs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mexus/procinfo-rs/git/refs{/sha}","trees_url":"https://api.github.com/repos/mexus/procinfo-rs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mexus/procinfo-rs/statuses/{sha}","languages_url":"https://api.github.com/repos/mexus/procinfo-rs/languages","stargazers_url":"https://api.github.com/repos/mexus/procinfo-rs/stargazers","contributors_url":"https://api.github.com/repos/mexus/procinfo-rs/contributors","subscribers_url":"https://api.github.com/repos/mexus/procinfo-rs/subscribers","subscription_url":"https://api.github.com/repos/mexus/procinfo-rs/subscription","commits_url":"https://api.github.com/repos/mexus/procinfo-rs/commits{/sha}","git_commits_url":"https://api.github.com/repos/mexus/procinfo-rs/git/commits{/sha}","comments_url":"https://api.github.com/repos/mexus/procinfo-rs/comments{/number}","issue_comment_url":"https://api.github.com/repos/mexus/procinfo-rs/issues/comments{/number}","contents_url":"https://api.github.com/repos/mexus/procinfo-rs/contents/{+path}","compare_url":"https://api.github.com/repos/mexus/procinfo-rs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mexus/procinfo-rs/merges","archive_url":"https://api.github.com/repos/mexus/procinfo-rs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mexus/procinfo-rs/downloads","issues_url":"https://api.github.com/repos/mexus/procinfo-rs/issues{/number}","pulls_url":"https://api.github.com/repos/mexus/procinfo-rs/pulls{/number}","milestones_url":"https://api.github.com/repos/mexus/procinfo-rs/milestones{/number}","notifications_url":"https://api.github.com/repos/mexus/procinfo-rs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mexus/procinfo-rs/labels{/name}","releases_url":"https://api.github.com/repos/mexus/procinfo-rs/releases{/id}","deployments_url":"https://api.github.com/repos/mexus/procinfo-rs/deployments","created_at":"2017-08-25T23:27:57Z","updated_at":"2017-08-25T23:27:58Z","pushed_at":"2017-08-27T21:25:59Z","git_url":"git://github.com/mexus/procinfo-rs.git","ssh_url":"git@github.com:mexus/procinfo-rs.git","clone_url":"https://github.com/mexus/procinfo-rs.git","svn_url":"https://github.com/mexus/procinfo-rs","homepage":"","size":87,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"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":"danburkert:master","ref":"master","sha":"32aa416581c13647da6a86b6911ebd5885f92cfe","user":{"login":"danburkert","id":160242,"avatar_url":"https://avatars0.githubusercontent.com/u/160242?v=4","gravatar_id":"","url":"https://api.github.com/users/danburkert","html_url":"https://github.com/danburkert","followers_url":"https://api.github.com/users/danburkert/followers","following_url":"https://api.github.com/users/danburkert/following{/other_user}","gists_url":"https://api.github.com/users/danburkert/gists{/gist_id}","starred_url":"https://api.github.com/users/danburkert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danburkert/subscriptions","organizations_url":"https://api.github.com/users/danburkert/orgs","repos_url":"https://api.github.com/users/danburkert/repos","events_url":"https://api.github.com/users/danburkert/events{/privacy}","received_events_url":"https://api.github.com/users/danburkert/received_events","type":"User","site_admin":false},"repo":{"id":41143291,"name":"procinfo-rs","full_name":"danburkert/procinfo-rs","owner":{"login":"danburkert","id":160242,"avatar_url":"https://avatars0.githubusercontent.com/u/160242?v=4","gravatar_id":"","url":"https://api.github.com/users/danburkert","html_url":"https://github.com/danburkert","followers_url":"https://api.github.com/users/danburkert/followers","following_url":"https://api.github.com/users/danburkert/following{/other_user}","gists_url":"https://api.github.com/users/danburkert/gists{/gist_id}","starred_url":"https://api.github.com/users/danburkert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danburkert/subscriptions","organizations_url":"https://api.github.com/users/danburkert/orgs","repos_url":"https://api.github.com/users/danburkert/repos","events_url":"https://api.github.com/users/danburkert/events{/privacy}","received_events_url":"https://api.github.com/users/danburkert/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/danburkert/procinfo-rs","description":"A Rust library for accessing Linux process and system information","fork":false,"url":"https://api.github.com/repos/danburkert/procinfo-rs","forks_url":"https://api.github.com/repos/danburkert/procinfo-rs/forks","keys_url":"https://api.github.com/repos/danburkert/procinfo-rs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/danburkert/procinfo-rs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/danburkert/procinfo-rs/teams","hooks_url":"https://api.github.com/repos/danburkert/procinfo-rs/hooks","issue_events_url":"https://api.github.com/repos/danburkert/procinfo-rs/issues/events{/number}","events_url":"https://api.github.com/repos/danburkert/procinfo-rs/events","assignees_url":"https://api.github.com/repos/danburkert/procinfo-rs/assignees{/user}","branches_url":"https://api.github.com/repos/danburkert/procinfo-rs/branches{/branch}","tags_url":"https://api.github.com/repos/danburkert/procinfo-rs/tags","blobs_url":"https://api.github.com/repos/danburkert/procinfo-rs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/danburkert/procinfo-rs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/danburkert/procinfo-rs/git/refs{/sha}","trees_url":"https://api.github.com/repos/danburkert/procinfo-rs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/danburkert/procinfo-rs/statuses/{sha}","languages_url":"https://api.github.com/repos/danburkert/procinfo-rs/languages","stargazers_url":"https://api.github.com/repos/danburkert/procinfo-rs/stargazers","contributors_url":"https://api.github.com/repos/danburkert/procinfo-rs/contributors","subscribers_url":"https://api.github.com/repos/danburkert/procinfo-rs/subscribers","subscription_url":"https://api.github.com/repos/danburkert/procinfo-rs/subscription","commits_url":"https://api.github.com/repos/danburkert/procinfo-rs/commits{/sha}","git_commits_url":"https://api.github.com/repos/danburkert/procinfo-rs/git/commits{/sha}","comments_url":"https://api.github.com/repos/danburkert/procinfo-rs/comments{/number}","issue_comment_url":"https://api.github.com/repos/danburkert/procinfo-rs/issues/comments{/number}","contents_url":"https://api.github.com/repos/danburkert/procinfo-rs/contents/{+path}","compare_url":"https://api.github.com/repos/danburkert/procinfo-rs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/danburkert/procinfo-rs/merges","archive_url":"https://api.github.com/repos/danburkert/procinfo-rs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/danburkert/procinfo-rs/downloads","issues_url":"https://api.github.com/repos/danburkert/procinfo-rs/issues{/number}","pulls_url":"https://api.github.com/repos/danburkert/procinfo-rs/pulls{/number}","milestones_url":"https://api.github.com/repos/danburkert/procinfo-rs/milestones{/number}","notifications_url":"https://api.github.com/repos/danburkert/procinfo-rs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/danburkert/procinfo-rs/labels{/name}","releases_url":"https://api.github.com/repos/danburkert/procinfo-rs/releases{/id}","deployments_url":"https://api.github.com/repos/danburkert/procinfo-rs/deployments","created_at":"2015-08-21T07:55:42Z","updated_at":"2017-08-26T01:51:01Z","pushed_at":"2017-08-27T21:26:01Z","git_url":"git://github.com/danburkert/procinfo-rs.git","ssh_url":"git@github.com:danburkert/procinfo-rs.git","clone_url":"https://github.com/danburkert/procinfo-rs.git","svn_url":"https://github.com/danburkert/procinfo-rs","homepage":"","size":84,"stargazers_count":41,"watchers_count":41,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":14,"mirror_url":null,"open_issues_count":2,"forks":14,"open_issues":2,"watchers":41,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/danburkert/procinfo-rs/pulls/28"},"html":{"href":"https://github.com/danburkert/procinfo-rs/pull/28"},"issue":{"href":"https://api.github.com/repos/danburkert/procinfo-rs/issues/28"},"comments":{"href":"https://api.github.com/repos/danburkert/procinfo-rs/issues/28/comments"},"review_comments":{"href":"https://api.github.com/repos/danburkert/procinfo-rs/pulls/28/comments"},"review_comment":{"href":"https://api.github.com/repos/danburkert/procinfo-rs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/danburkert/procinfo-rs/pulls/28/commits"},"statuses":{"href":"https://api.github.com/repos/danburkert/procinfo-rs/statuses/7fc92bb8ccc5c7c7a9c219a4d4b1f93f43e3c9e8"}}}}
{"actor":{"display_login":"mexus"}}