Merge pull request #4 from aldanor/feature/pub-bytes
Make `qoi::decode::Bytes` pub + clippy fixes
This commit is contained in:
commit
e97077e527
7 changed files with 22 additions and 15 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -13,7 +13,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
rust: [stable, beta, nightly, 1.51.0] # MSRV=1.51
|
rust: [stable, beta, nightly, 1.61.0] # MSRV=1.61
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with: {submodules: true}
|
with: {submodules: true}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
[package]
|
[package]
|
||||||
name = "qoi"
|
name = "qoi"
|
||||||
version = "0.4.0"
|
version = "0.4.1"
|
||||||
description = "VERY fast encoder/decoder for QOI (Quite Okay Image) format"
|
description = "VERY fast encoder/decoder for QOI (Quite Okay Image) format"
|
||||||
authors = ["Ivan Smirnov <rust@ivan.smirnov.ie>"]
|
authors = ["Ivan Smirnov <rust@ivan.smirnov.ie>"]
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
repository = "https://github.com/aldanor/qoi-rust"
|
repository = "https://github.com/aldanor/qoi-rust"
|
||||||
|
@ -14,7 +14,7 @@ keywords = ["qoi", "graphics", "image", "encoding"]
|
||||||
exclude = [
|
exclude = [
|
||||||
"assets/*",
|
"assets/*",
|
||||||
]
|
]
|
||||||
rust-version = "1.51.0"
|
rust-version = "1.61.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
|
@ -23,7 +23,7 @@ std = [] # std mode (enabled by default) - provides access to `std::io`,
|
||||||
reference = [] # follows reference encoder implementation precisely, but may be slightly slower
|
reference = [] # follows reference encoder implementation precisely, but may be slightly slower
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bytemuck = "1.7"
|
bytemuck = "1.12"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["libqoi", "bench"]
|
members = ["libqoi", "bench"]
|
||||||
|
|
|
@ -51,8 +51,7 @@ this library proved to be the fastest one by a noticeable margin.
|
||||||
|
|
||||||
### Rust version
|
### Rust version
|
||||||
|
|
||||||
The minimum required Rust version is 1.51.0 (any changes to this would be
|
The minimum required Rust version for the latest crate version is 1.61.0.
|
||||||
considered to be a breaking change).
|
|
||||||
|
|
||||||
### `no_std`
|
### `no_std`
|
||||||
|
|
||||||
|
|
|
@ -230,7 +230,7 @@ pub trait Reader: Sized {
|
||||||
fn decode_image(&mut self, out: &mut [u8], channels: u8, src_channels: u8) -> Result<()>;
|
fn decode_image(&mut self, out: &mut [u8], channels: u8, src_channels: u8) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Bytes<'a>(&'a [u8]);
|
pub struct Bytes<'a>(&'a [u8]);
|
||||||
|
|
||||||
impl<'a> Bytes<'a> {
|
impl<'a> Bytes<'a> {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -318,12 +318,13 @@ impl<R: Read> Decoder<R> {
|
||||||
|
|
||||||
/// Returns an immutable reference to the underlying reader.
|
/// Returns an immutable reference to the underlying reader.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn reader(&self) -> &R {
|
pub const fn reader(&self) -> &R {
|
||||||
&self.reader
|
&self.reader
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consumes the decoder and returns the underlying reader back.
|
/// Consumes the decoder and returns the underlying reader back.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[allow(clippy::missing_const_for_fn)]
|
||||||
pub fn into_reader(self) -> R {
|
pub fn into_reader(self) -> R {
|
||||||
self.reader
|
self.reader
|
||||||
}
|
}
|
||||||
|
@ -343,7 +344,7 @@ impl<R: Reader> Decoder<R> {
|
||||||
/// to decode RGB into RGBA (in which case the alpha channel will be set
|
/// to decode RGB into RGBA (in which case the alpha channel will be set
|
||||||
/// to 255), and vice versa (in which case the alpha channel will be ignored).
|
/// to 255), and vice versa (in which case the alpha channel will be ignored).
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn with_channels(mut self, channels: Channels) -> Self {
|
pub const fn with_channels(mut self, channels: Channels) -> Self {
|
||||||
self.channels = channels;
|
self.channels = channels;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -352,13 +353,13 @@ impl<R: Reader> Decoder<R> {
|
||||||
///
|
///
|
||||||
/// Note: this may differ from the number of channels specified in the header.
|
/// Note: this may differ from the number of channels specified in the header.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn channels(&self) -> Channels {
|
pub const fn channels(&self) -> Channels {
|
||||||
self.channels
|
self.channels
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the decoded image header.
|
/// Returns the decoded image header.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn header(&self) -> &Header {
|
pub const fn header(&self) -> &Header {
|
||||||
&self.header
|
&self.header
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,7 +367,7 @@ impl<R: Reader> Decoder<R> {
|
||||||
///
|
///
|
||||||
/// Can be used to pre-allocate the buffer to decode the image into.
|
/// Can be used to pre-allocate the buffer to decode the image into.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn required_buf_len(&self) -> usize {
|
pub const fn required_buf_len(&self) -> usize {
|
||||||
self.header.n_pixels().saturating_mul(self.channels.as_u8() as usize)
|
self.header.n_pixels().saturating_mul(self.channels.as_u8() as usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,8 @@
|
||||||
clippy::must_use_candidate,
|
clippy::must_use_candidate,
|
||||||
clippy::module_name_repetitions,
|
clippy::module_name_repetitions,
|
||||||
clippy::cargo_common_metadata,
|
clippy::cargo_common_metadata,
|
||||||
clippy::doc_markdown
|
clippy::doc_markdown,
|
||||||
|
clippy::return_self_not_must_use,
|
||||||
)]
|
)]
|
||||||
#![cfg_attr(not(any(feature = "std", test)), no_std)]
|
#![cfg_attr(not(any(feature = "std", test)), no_std)]
|
||||||
#[cfg(all(feature = "alloc", not(any(feature = "std", test))))]
|
#[cfg(all(feature = "alloc", not(any(feature = "std", test))))]
|
||||||
|
|
|
@ -84,7 +84,7 @@ pub struct GenericWriter<W> {
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl<W: Write> GenericWriter<W> {
|
impl<W: Write> GenericWriter<W> {
|
||||||
pub fn new(writer: W) -> Self {
|
pub const fn new(writer: W) -> Self {
|
||||||
Self { writer, n_written: 0 }
|
Self { writer, n_written: 0 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
tests/test_misc.rs
Normal file
6
tests/test_misc.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#[test]
|
||||||
|
fn test_new_encoder() {
|
||||||
|
// this used to fail due to `Bytes` not being `pub`
|
||||||
|
let arr = [0u8];
|
||||||
|
let _ = qoi::Decoder::new(&arr[..]);
|
||||||
|
}
|
Loading…
Reference in a new issue