Skip to content

Commit a87ce26

Browse files
cgzonesotavio
authored andcommitted
Drop unnecessary lifetime annotations
The 'static lifetime annotations on ArchiveIterator::read_from() hinder the usage on non-local variables, e.g. a given slice of bytes wrapped in std::core::Cursor.
1 parent 1319dd6 commit a87ce26

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
* Raise MSRV to 1.59.0
88
* Change to 2021 edition
9+
* Drop lifetime annotations of reader parameter in `ArchiveIterator::from_read`
10+
and `ArchiveIterator::from_read_with_encoding` [#90]
911

1012
## [0.13.0] - 2022-08-03
1113

src/iterator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<R: Read + Seek> ArchiveIterator<R> {
126126
/// ```
127127
pub fn from_read_with_encoding(source: R, decode: DecodeCallback) -> Result<ArchiveIterator<R>>
128128
where
129-
R: Read + Seek + 'static,
129+
R: Read + Seek,
130130
{
131131
let utf8_guard = ffi::UTF8LocaleGuard::new();
132132
let reader = source;
@@ -231,7 +231,7 @@ impl<R: Read + Seek> ArchiveIterator<R> {
231231
/// ```
232232
pub fn from_read(source: R) -> Result<ArchiveIterator<R>>
233233
where
234-
R: Read + Seek + 'static,
234+
R: Read + Seek,
235235
{
236236
ArchiveIterator::from_read_with_encoding(source, crate::decode_utf8)
237237
}

tests/integration_test.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
// SPDX-License-Identifier: MIT OR Apache-2.0
44

55
use compress_tools::*;
6-
use std::path::Path;
6+
use std::{
7+
io::{Cursor, Read},
8+
path::Path,
9+
};
710

811
#[test]
912
fn get_compressed_file_content() {
@@ -631,6 +634,28 @@ fn iterate_truncated_archive() {
631634
panic!("Did not find expected error");
632635
}
633636

637+
fn uncompress_bytes_helper(bytes: &[u8]) {
638+
let wrapper = Cursor::new(bytes);
639+
640+
for content in ArchiveIterator::from_read(wrapper).unwrap() {
641+
if let ArchiveContents::Err(Error::Unknown) = content {
642+
return;
643+
}
644+
}
645+
646+
panic!("Did not find expected error");
647+
}
648+
649+
#[test]
650+
fn uncompress_bytes() {
651+
let mut source = std::fs::File::open("tests/fixtures/truncated.log.gz").unwrap();
652+
653+
let mut buffer = Vec::new();
654+
source.read_to_end(&mut buffer).unwrap();
655+
656+
uncompress_bytes_helper(&buffer)
657+
}
658+
634659
#[test]
635660
fn uncompress_archive_zip_slip_vulnerability() {
636661
uncompress_archive(

0 commit comments

Comments
 (0)