Skip to content

Commit 786feac

Browse files
committed
deprecate Compression::new
1 parent 15258fe commit 786feac

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/lib.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,28 +82,39 @@ pub mod write;
8282
pub struct Compression(u32);
8383

8484
impl Compression {
85-
/// Create a new compression spec with a specific numeric level (0-9).
85+
/// Create a new compression spec with a specific numeric level in the range `1..=9`.
86+
#[deprecated(since = "0.5.1", note = "use try_new instead")]
8687
pub fn new(level: u32) -> Compression {
8788
Compression(level)
8889
}
8990

9091
/// Do not compress.
92+
#[deprecated(since = "0.5.1", note = "libbz2 does not support compresson level 0")]
9193
pub fn none() -> Compression {
9294
Compression(0)
9395
}
9496

97+
/// Create a new compression spec with a specific numeric level in the range `1..=9`.
98+
pub const fn try_new(level: u32) -> Option<Compression> {
99+
if level >= 1 && level <= 9 {
100+
Some(Compression(level))
101+
} else {
102+
None
103+
}
104+
}
105+
95106
/// Optimize for the best speed of encoding.
96-
pub fn fast() -> Compression {
107+
pub const fn fast() -> Compression {
97108
Compression(1)
98109
}
99110

100-
/// Optimize for the size of data being encoded.
101-
pub fn best() -> Compression {
111+
/// Optimize for smallest output size.
112+
pub const fn best() -> Compression {
102113
Compression(9)
103114
}
104115

105116
/// Return the compression level as an integer.
106-
pub fn level(&self) -> u32 {
117+
pub const fn level(&self) -> u32 {
107118
self.0
108119
}
109120
}

0 commit comments

Comments
 (0)