Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade MSRV to 1.83.0 and implement Error from core::error #267

Merged
merged 2 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,21 @@ jobs:
- name: Install Rust toolchain
uses: artichoke/setup-rust/[email protected]
with:
toolchain: "1.42.0"
toolchain: "1.83.0"

- name: Compile
run: cargo build --verbose

# skip tests because dev dependencies have a higher MSRV than boba does.
- name: Compile tests
if: false
run: cargo test --no-run

- name: Test
if: false
run: cargo test

- name: Test with all features
if: false
run: cargo test --all-features

- name: Test with no default features
if: false
run: cargo test --no-default-features

rust-minimal-versions:
Expand Down
8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name = "boba"
version = "5.0.0" # remember to set `html_root_url` in `src/lib.rs`.
authors = ["Ryan Lopopolo <[email protected]>"]
license = "MIT"
edition = "2018"
rust-version = "1.42.0"
edition = "2021"
rust-version = "1.83.0"
readme = "README.md"
repository = "https://github.com/artichoke/boba"
documentation = "https://docs.rs/boba"
Expand All @@ -15,10 +15,6 @@ categories = ["encoding", "no-std"]
include = ["src/**/*", "tests/**/*", "LICENSE", "README.md"]

[features]
default = ["std"]
# Enable dependency on `std`, the Rust standard library. This feature enables
# `std::error::Error` implementations on the error types in `boba`.
std = []

[dependencies]

Expand Down
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,11 @@ assert_eq!(boba::decode(b"xexax"), Ok(vec![]));

Boba is `no_std` compatible with a required dependency on the [`alloc`] crate.

Boba has several Cargo features, all of which are enabled by default:

- **std** - Adds a dependency on [`std`], the Rust Standard Library. This
feature enables [`std::error::Error`] implementations on error types in this
crate. Enabling the **std** feature also enables the **alloc** feature.

`boba` is [fuzzed](fuzz/fuzz_targets) with [cargo-fuzz].

## Minimum Rust Version Policy

This crate's minimum supported `rustc` version (MSRV) is `1.42.0`.
This crate's minimum supported `rustc` version (MSRV) is `1.83.0`.

MSRV may be bumped in minor version releases.

Expand Down
2 changes: 1 addition & 1 deletion src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn inner(encoded: &[u8]) -> Result<Vec<u8>, DecodeError> {
if let Some((_, pos)) = enc
.iter()
.zip(1_usize..) // start `pos` at 1 because we stripped off a leading 'x'
.find(|(&byte, _)| ALPHABET_TABLE[usize::from(byte)] == 0)
.find(|&(&byte, _)| ALPHABET_TABLE[usize::from(byte)] == 0)
{
return Err(DecodeError::InvalidByte(pos));
}
Expand Down
46 changes: 10 additions & 36 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#![warn(missing_docs)]
#![warn(missing_debug_implementations)]
#![warn(rust_2018_idioms)]
#![warn(rust_2021_compatibility)]
#![warn(rust_2024_compatibility)]
#![warn(trivial_casts, trivial_numeric_casts)]
#![warn(unused_qualifications)]
#![warn(variant_size_differences)]
Expand All @@ -28,6 +30,9 @@
//! Bubble Babble is part of the Digest libraries in [Perl][perl-bubblebabble]
//! and [Ruby][ruby-bubblebabble].
//!
//! [perl-bubblebabble]: https://metacpan.org/pod/Digest::BubbleBabble
//! [ruby-bubblebabble]: https://ruby-doc.org/stdlib-3.1.1/libdoc/digest/rdoc/Digest.html#method-c-bubblebabble
//!
//! # Usage
//!
//! You can encode binary data by calling [`encode`](encode()):
Expand Down Expand Up @@ -64,31 +69,11 @@
//!
//! Boba is `no_std` compatible with a required dependency on the [`alloc`]
//! crate.
//!
//! Boba has several Cargo features, all of which are enabled by default:
//!
//! - **std** - Adds a dependency on [`std`], the Rust Standard Library. This
//! feature enables [`std::error::Error`] implementations on error types in
//! this crate. Enabling the **std** feature also enables the **alloc**
//! feature.
//!
#![cfg_attr(
not(feature = "std"),
doc = "[`std`]: https://doc.rust-lang.org/stable/std/index.html"
)]
#![cfg_attr(
not(feature = "std"),
doc = "[`std::error::Error`]: https://doc.rust-lang.org/stable/std/error/trait.Error.html"
)]
//! [perl-bubblebabble]: https://metacpan.org/pod/Digest::BubbleBabble
//! [ruby-bubblebabble]: https://ruby-doc.org/stdlib-3.1.1/libdoc/digest/rdoc/Digest.html#method-c-bubblebabble

#![no_std]
#![doc(html_root_url = "https://docs.rs/boba/5.0.0")]

extern crate alloc;
#[cfg(feature = "std")]
extern crate std;

use alloc::string::String;
use alloc::vec::Vec;
Expand Down Expand Up @@ -140,8 +125,7 @@ pub enum DecodeError {
MalformedTrailer,
}

#[cfg(feature = "std")]
impl std::error::Error for DecodeError {}
impl core::error::Error for DecodeError {}

impl fmt::Display for DecodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand All @@ -152,8 +136,7 @@ impl fmt::Display for DecodeError {
Self::ExpectedVowel => f.write_str("Expected vowel, got something else"),
Self::InvalidByte(pos) => write!(
f,
"Encountered byte outside of encoding alphabet at position {}",
pos
"Encountered byte outside of encoding alphabet at position {pos}"
),
Self::MalformedHeader => f.write_str("Missing required 'x' header"),
Self::MalformedTrailer => f.write_str("Missing required 'x' trailer"),
Expand Down Expand Up @@ -332,7 +315,7 @@ mod tests {
];
for tc in test_cases {
let mut buf = String::new();
write!(&mut buf, "{}", tc).unwrap();
write!(&mut buf, "{tc}").unwrap();
assert!(!buf.is_empty());
}
}
Expand All @@ -355,14 +338,5 @@ mod tests {
// This module and macro declaration should be kept at the end of the file, in
// order to not interfere with code coverage.
#[cfg(doctest)]
macro_rules! readme {
($x:expr) => {
#[doc = $x]
mod readme {}
};
() => {
readme!(include_str!("../README.md"));
};
}
#[cfg(doctest)]
readme!();
#[doc = include_str!("../README.md")]
mod readme {}