Skip to content

Commit e97077e

Browse files
authored
Merge pull request #4 from aldanor/feature/pub-bytes
Make `qoi::decode::Bytes` pub + clippy fixes
2 parents 53ecac3 + fe83d1b commit e97077e

File tree

7 files changed

+22
-15
lines changed

7 files changed

+22
-15
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
rust: [stable, beta, nightly, 1.51.0] # MSRV=1.51
16+
rust: [stable, beta, nightly, 1.61.0] # MSRV=1.61
1717
steps:
1818
- uses: actions/checkout@v2
1919
with: {submodules: true}

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
22
name = "qoi"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
description = "VERY fast encoder/decoder for QOI (Quite Okay Image) format"
55
authors = ["Ivan Smirnov <[email protected]>"]
6-
edition = "2018"
6+
edition = "2021"
77
readme = "README.md"
88
license = "MIT/Apache-2.0"
99
repository = "https://github.com/aldanor/qoi-rust"
@@ -14,7 +14,7 @@ keywords = ["qoi", "graphics", "image", "encoding"]
1414
exclude = [
1515
"assets/*",
1616
]
17-
rust-version = "1.51.0"
17+
rust-version = "1.61.0"
1818

1919
[features]
2020
default = ["std"]
@@ -23,7 +23,7 @@ std = [] # std mode (enabled by default) - provides access to `std::io`,
2323
reference = [] # follows reference encoder implementation precisely, but may be slightly slower
2424

2525
[dependencies]
26-
bytemuck = "1.7"
26+
bytemuck = "1.12"
2727

2828
[workspace]
2929
members = ["libqoi", "bench"]

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ this library proved to be the fastest one by a noticeable margin.
5151

5252
### Rust version
5353

54-
The minimum required Rust version is 1.51.0 (any changes to this would be
55-
considered to be a breaking change).
54+
The minimum required Rust version for the latest crate version is 1.61.0.
5655

5756
### `no_std`
5857

src/decode.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ pub trait Reader: Sized {
230230
fn decode_image(&mut self, out: &mut [u8], channels: u8, src_channels: u8) -> Result<()>;
231231
}
232232

233-
struct Bytes<'a>(&'a [u8]);
233+
pub struct Bytes<'a>(&'a [u8]);
234234

235235
impl<'a> Bytes<'a> {
236236
#[inline]
@@ -318,12 +318,13 @@ impl<R: Read> Decoder<R> {
318318

319319
/// Returns an immutable reference to the underlying reader.
320320
#[inline]
321-
pub fn reader(&self) -> &R {
321+
pub const fn reader(&self) -> &R {
322322
&self.reader
323323
}
324324

325325
/// Consumes the decoder and returns the underlying reader back.
326326
#[inline]
327+
#[allow(clippy::missing_const_for_fn)]
327328
pub fn into_reader(self) -> R {
328329
self.reader
329330
}
@@ -343,7 +344,7 @@ impl<R: Reader> Decoder<R> {
343344
/// to decode RGB into RGBA (in which case the alpha channel will be set
344345
/// to 255), and vice versa (in which case the alpha channel will be ignored).
345346
#[inline]
346-
pub fn with_channels(mut self, channels: Channels) -> Self {
347+
pub const fn with_channels(mut self, channels: Channels) -> Self {
347348
self.channels = channels;
348349
self
349350
}
@@ -352,21 +353,21 @@ impl<R: Reader> Decoder<R> {
352353
///
353354
/// Note: this may differ from the number of channels specified in the header.
354355
#[inline]
355-
pub fn channels(&self) -> Channels {
356+
pub const fn channels(&self) -> Channels {
356357
self.channels
357358
}
358359

359360
/// Returns the decoded image header.
360361
#[inline]
361-
pub fn header(&self) -> &Header {
362+
pub const fn header(&self) -> &Header {
362363
&self.header
363364
}
364365

365366
/// The number of bytes the decoded image will take.
366367
///
367368
/// Can be used to pre-allocate the buffer to decode the image into.
368369
#[inline]
369-
pub fn required_buf_len(&self) -> usize {
370+
pub const fn required_buf_len(&self) -> usize {
370371
self.header.n_pixels().saturating_mul(self.channels.as_u8() as usize)
371372
}
372373

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
clippy::must_use_candidate,
6363
clippy::module_name_repetitions,
6464
clippy::cargo_common_metadata,
65-
clippy::doc_markdown
65+
clippy::doc_markdown,
66+
clippy::return_self_not_must_use,
6667
)]
6768
#![cfg_attr(not(any(feature = "std", test)), no_std)]
6869
#[cfg(all(feature = "alloc", not(any(feature = "std", test))))]

src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub struct GenericWriter<W> {
8484

8585
#[cfg(feature = "std")]
8686
impl<W: Write> GenericWriter<W> {
87-
pub fn new(writer: W) -> Self {
87+
pub const fn new(writer: W) -> Self {
8888
Self { writer, n_written: 0 }
8989
}
9090
}

tests/test_misc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[test]
2+
fn test_new_encoder() {
3+
// this used to fail due to `Bytes` not being `pub`
4+
let arr = [0u8];
5+
let _ = qoi::Decoder::new(&arr[..]);
6+
}

0 commit comments

Comments
 (0)