{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rfcs/issues/1376","labels_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1376/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1376/comments","events_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1376/events","html_url":"https://github.com/rust-lang/rfcs/issues/1376","id":118301393,"number":1376,"title":"Common Truncate trait","user":{"login":"Undeterminant","id":1756968,"avatar_url":"https://avatars.githubusercontent.com/u/1756968?v=3","gravatar_id":"","url":"https://api.github.com/users/Undeterminant","html_url":"https://github.com/Undeterminant","followers_url":"https://api.github.com/users/Undeterminant/followers","following_url":"https://api.github.com/users/Undeterminant/following{/other_user}","gists_url":"https://api.github.com/users/Undeterminant/gists{/gist_id}","starred_url":"https://api.github.com/users/Undeterminant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Undeterminant/subscriptions","organizations_url":"https://api.github.com/users/Undeterminant/orgs","repos_url":"https://api.github.com/users/Undeterminant/repos","events_url":"https://api.github.com/users/Undeterminant/events{/privacy}","received_events_url":"https://api.github.com/users/Undeterminant/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-11-23T00:33:23Z","updated_at":"2015-11-24T08:08:18Z","closed_at":null,"body":"I'd like to be able to generalise `File` using `io::Read`, `io::Write`, and `io::Seek` instead, but there's no common interface for truncating such an object. For example, it's useful to test file reads/writes on a `Vec`, but I can't ever reduce the size of the object if I delete data. This function is called `set_len` for files and `truncate` for `Vec`.\r\n\r\nMy best option right now is to make a Trait like so:\r\n```\r\ntrait Truncate {\r\n  fn truncate_len(&mut self, len: usize) -> io::Result<()>;\r\n}\r\nimpl Truncate for File {\r\n  fn truncate_len(&mut self, len: usize) -> io::Result<()> { self.set_len(len) }\r\n}\r\nimpl Truncate for Vec<u8> {\r\n  fn truncate_len(&mut self, len: usize) -> io::Result<()> { Ok(self.truncate(len)) }\r\n}\r\n```\r\n\r\nIt'd be great to have something similar be part of `std::io` with support for more structs."},"comment":{"url":"https://api.github.com/repos/rust-lang/rfcs/issues/comments/159190545","html_url":"https://github.com/rust-lang/rfcs/issues/1376#issuecomment-159190545","issue_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1376","id":159190545,"user":{"login":"oli-obk","id":332036,"avatar_url":"https://avatars.githubusercontent.com/u/332036?v=3","gravatar_id":"","url":"https://api.github.com/users/oli-obk","html_url":"https://github.com/oli-obk","followers_url":"https://api.github.com/users/oli-obk/followers","following_url":"https://api.github.com/users/oli-obk/following{/other_user}","gists_url":"https://api.github.com/users/oli-obk/gists{/gist_id}","starred_url":"https://api.github.com/users/oli-obk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oli-obk/subscriptions","organizations_url":"https://api.github.com/users/oli-obk/orgs","repos_url":"https://api.github.com/users/oli-obk/repos","events_url":"https://api.github.com/users/oli-obk/events{/privacy}","received_events_url":"https://api.github.com/users/oli-obk/received_events","type":"User","site_admin":false},"created_at":"2015-11-24T08:08:18Z","updated_at":"2015-11-24T08:08:18Z","body":"many things do, still it's better to have a working version in a crate (in case that is doable, which it is in this case)."}}