Skip to content

Commit 405652f

Browse files
committed
feat: make it easier to use Detector::default()
1 parent 55ccd32 commit 405652f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

common/src/compression/detecting.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,21 @@ pub struct Detector<'a> {
117117

118118
impl<'a> Detector<'a> {
119119
/// Detect and decompress in a single step.
120-
pub fn decompress(&'a self, data: Bytes) -> Result<Bytes, Error<'a>> {
120+
pub fn decompress(&self, data: Bytes) -> Result<Bytes, Error<'a>> {
121121
self.decompress_with(data, &Default::default())
122122
}
123123

124124
/// Detect and decompress in a single step.
125125
pub fn decompress_with(
126-
&'a self,
126+
&self,
127127
data: Bytes,
128128
opts: &DecompressionOptions,
129129
) -> Result<Bytes, Error<'a>> {
130130
let compression = self.detect(&data)?;
131131
Ok(compression.decompress_with(data, opts)?)
132132
}
133133

134-
pub fn detect(&'a self, #[allow(unused)] data: &[u8]) -> Result<Compression, Error<'a>> {
134+
pub fn detect(&self, #[allow(unused)] data: &[u8]) -> Result<Compression, Error<'a>> {
135135
// detect by file name extension
136136

137137
if let Some(file_name) = self.file_name {
@@ -218,4 +218,13 @@ mod test {
218218
fn by_name_gzip() {
219219
assert_eq!(detect("foo.bar.gz"), Compression::Gzip);
220220
}
221+
222+
#[test]
223+
fn default() {
224+
// we're not interested in running this, just ensuring we can use the Default ergonomically
225+
let _result = Detector::default().decompress(Bytes::from_static(b"foo"));
226+
227+
let detector = Detector::default();
228+
let _result = detector.decompress(Bytes::from_static(b"foo"));
229+
}
221230
}

0 commit comments

Comments
 (0)