{"action":"created","issue":{"url":"https://api.github.com/repos/jeremyletang/rust-portaudio/issues/82","labels_url":"https://api.github.com/repos/jeremyletang/rust-portaudio/issues/82/labels{/name}","comments_url":"https://api.github.com/repos/jeremyletang/rust-portaudio/issues/82/comments","events_url":"https://api.github.com/repos/jeremyletang/rust-portaudio/issues/82/events","html_url":"https://github.com/jeremyletang/rust-portaudio/issues/82","id":70871841,"number":82,"title":"Add a `PortAudio` type for safer, automatic initialisation and termination of PortAudio.","user":{"login":"mitchmindtree","id":4587373,"avatar_url":"https://avatars.githubusercontent.com/u/4587373?v=3","gravatar_id":"","url":"https://api.github.com/users/mitchmindtree","html_url":"https://github.com/mitchmindtree","followers_url":"https://api.github.com/users/mitchmindtree/followers","following_url":"https://api.github.com/users/mitchmindtree/following{/other_user}","gists_url":"https://api.github.com/users/mitchmindtree/gists{/gist_id}","starred_url":"https://api.github.com/users/mitchmindtree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitchmindtree/subscriptions","organizations_url":"https://api.github.com/users/mitchmindtree/orgs","repos_url":"https://api.github.com/users/mitchmindtree/repos","events_url":"https://api.github.com/users/mitchmindtree/events{/privacy}","received_events_url":"https://api.github.com/users/mitchmindtree/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jeremyletang/rust-portaudio/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-25T07:56:03Z","updated_at":"2015-04-25T08:02:27Z","closed_at":null,"body":"At the moment a user must initialise and terminate PortAudio manually with the `initialize` and `terminate` functions. This makes it easy to forget to release resources or for a stream to accidentally outlive PortAudio's termination.\r\n\r\nI propose that we create a `PortAudio` type whose constructor calls `pa::initialize()` and destructor calls `pa::terminate()`. We could also move many of the library's functions onto `PortAudio` methods. i.e if we had\r\n```Rust\r\nlet pa = PortAudio::new();\r\n````\r\nthen\r\n```Rust\r\nlet stream = pa::Stream::new();\r\n```\r\nwould become\r\n```Rust\r\nlet stream = pa.new_stream();\r\n```\r\nThis is strictly safer because:\r\n1. A `Stream` cannot be created without `PortAudio` being initialised and\r\n2. A `Stream`'s lifetime could be limited to that of the PortAudio type, ensuring that no streams outlive the `PortAudio` type (and in turn `pa::terminate`)."},"comment":{"url":"https://api.github.com/repos/jeremyletang/rust-portaudio/issues/comments/96151710","html_url":"https://github.com/jeremyletang/rust-portaudio/issues/82#issuecomment-96151710","issue_url":"https://api.github.com/repos/jeremyletang/rust-portaudio/issues/82","id":96151710,"user":{"login":"mitchmindtree","id":4587373,"avatar_url":"https://avatars.githubusercontent.com/u/4587373?v=3","gravatar_id":"","url":"https://api.github.com/users/mitchmindtree","html_url":"https://github.com/mitchmindtree","followers_url":"https://api.github.com/users/mitchmindtree/followers","following_url":"https://api.github.com/users/mitchmindtree/following{/other_user}","gists_url":"https://api.github.com/users/mitchmindtree/gists{/gist_id}","starred_url":"https://api.github.com/users/mitchmindtree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitchmindtree/subscriptions","organizations_url":"https://api.github.com/users/mitchmindtree/orgs","repos_url":"https://api.github.com/users/mitchmindtree/repos","events_url":"https://api.github.com/users/mitchmindtree/events{/privacy}","received_events_url":"https://api.github.com/users/mitchmindtree/received_events","type":"User","site_admin":false},"created_at":"2015-04-25T08:02:27Z","updated_at":"2015-04-25T08:02:27Z","body":"Although the API would look *slightly* different to the original C api (i.e. using methods instead of functions), I think the safety benefits far outweigh the familiarity issues, and this is after all why one would want to use Rust :)"}}