Common Truncate trait
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Description
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.
My best option right now is to make a Trait like so:
trait Truncate {
fn truncate_len(&mut self, len: usize) -> io::Result<()>;
}
impl Truncate for File {
fn truncate_len(&mut self, len: usize) -> io::Result<()> { self.set_len(len) }
}
impl Truncate for Vec<u8> {
fn truncate_len(&mut self, len: usize) -> io::Result<()> { Ok(self.resize(len)) }
}
It'd be great to have something similar be part of std::io with support for more structs.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the issue's proposed Truncate trait and the existing File::set_len and Vec::truncate APIs. Research how a common std::io abstraction could cover File, Vec, and other structs, then define the API, supported implementations, and acceptance criteria for a completed design.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend, operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100