{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/27799","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/27799/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/27799/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/27799/events","html_url":"https://github.com/rust-lang/rust/issues/27799","id":100694157,"number":27799,"title":"Tracking issue for Duration::span","user":{"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},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/B-unstable","name":"B-unstable","color":"e102d8"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/T-libs","name":"T-libs","color":"bfd4f2"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-13T05:38:59Z","updated_at":"2015-09-18T08:48:05Z","closed_at":null,"body":"This is a tracking issue for the unstable `duration_span` feature of the standard library. Known open questions are:\r\n\r\n* Is this the right place for this API?\r\n* Is this the right name?\r\n* Should the closure be able to return a value?\r\n* Should various other system clocks be exposed?"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/141384111","html_url":"https://github.com/rust-lang/rust/issues/27799#issuecomment-141384111","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/27799","id":141384111,"user":{"login":"SimonSapin","id":291359,"avatar_url":"https://avatars.githubusercontent.com/u/291359?v=3","gravatar_id":"","url":"https://api.github.com/users/SimonSapin","html_url":"https://github.com/SimonSapin","followers_url":"https://api.github.com/users/SimonSapin/followers","following_url":"https://api.github.com/users/SimonSapin/following{/other_user}","gists_url":"https://api.github.com/users/SimonSapin/gists{/gist_id}","starred_url":"https://api.github.com/users/SimonSapin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SimonSapin/subscriptions","organizations_url":"https://api.github.com/users/SimonSapin/orgs","repos_url":"https://api.github.com/users/SimonSapin/repos","events_url":"https://api.github.com/users/SimonSapin/events{/privacy}","received_events_url":"https://api.github.com/users/SimonSapin/received_events","type":"User","site_admin":false},"created_at":"2015-09-18T08:48:05Z","updated_at":"2015-09-18T08:48:05Z","body":"I suggest either:\r\n\r\n1. Moving `Duration::span` to a free function `std::time::span` and stabilize in 1.5;\r\n\r\n2. Or moving it to an associated function of a new `std::time::Timer` type like this:\r\n\r\n    ```rust\r\n    #[derive(Copy, Clone)]\r\n    pub struct Timer {\r\n        start_t: SteadyTime,\r\n    }\r\n\r\n    impl Timer {\r\n        pub fn start() -> Timer {\r\n            Timer {\r\n                start_t: SteadyTime::now(),\r\n            }\r\n        }\r\n\r\n        pub fn stop(&self) -> Duration {\r\n            &SteadyTime::now() - &self.start_t\r\n        }\r\n\r\n        pub fn span<F>(f: F) -> Duration where F: FnOnce() {\r\n            let timer = Timer::start();\r\n            f();\r\n            timer.stop()\r\n        }\r\n    }\r\n    ```\r\n    (Stability markers omitted for brevity.)\r\n\r\n    The idea is to generalize `span` to cases where the start and end point are not necessarily in the same stack frame, so a closure doesn’t work. Admittedly, this is theoretical. (I haven’t actually needed this myself so far.)"}}