From c18c614f322b289d79e01aef81d818c34c4d3df9 Mon Sep 17 00:00:00 2001 From: Demur Rumed Date: Wed, 8 Nov 2023 13:56:31 +0000 Subject: [PATCH 1/3] Update example to use clap v4, update criterion to 0.5, replace lazy_static with once_cell structopt crate was deprecated after being merged into clap v3 --- Cargo.toml | 10 +++++----- examples/base64.rs | 21 ++++++++------------- src/alphabet.rs | 9 +++++---- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dc9437b..f768cc3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,13 +35,13 @@ required-features = ["alloc"] rustdoc-args = ["--generate-link-to-definition"] [dev-dependencies] -criterion = "0.4.0" +criterion = "0.5" rand = { version = "0.8.5", features = ["small_rng"] } -structopt = "0.3.26" +clap = { version = "4", features = ["derive"] } # test fixtures for engine tests -rstest = "0.12.0" -rstest_reuse = "0.3.0" -lazy_static = "1.4.0" +rstest = "0.18.0" +rstest_reuse = "0.6.0" +once_cell = "1" [features] default = ["std"] diff --git a/examples/base64.rs b/examples/base64.rs index 0a214d2..d810243 100644 --- a/examples/base64.rs +++ b/examples/base64.rs @@ -5,20 +5,15 @@ use std::process; use std::str::FromStr; use base64::{alphabet, engine, read, write}; -use structopt::StructOpt; +use clap::{self, Parser}; -#[derive(Debug, StructOpt)] +#[derive(Copy, Clone, Debug, Default, Parser)] enum Alphabet { + #[default] Standard, UrlSafe, } -impl Default for Alphabet { - fn default() -> Self { - Self::Standard - } -} - impl FromStr for Alphabet { type Err = String; fn from_str(s: &str) -> Result { @@ -31,22 +26,22 @@ impl FromStr for Alphabet { } /// Base64 encode or decode FILE (or standard input), to standard output. -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] struct Opt { /// decode data - #[structopt(short = "d", long = "decode")] + #[arg(short, long)] decode: bool, /// The alphabet to choose. Defaults to the standard base64 alphabet. /// Supported alphabets include "standard" and "urlsafe". - #[structopt(long = "alphabet")] + #[arg(short, long)] alphabet: Option, /// The file to encode/decode. - #[structopt(parse(from_os_str))] + #[arg(short, long)] file: Option, } fn main() { - let opt = Opt::from_args(); + let opt = Opt::parse(); let stdin; let mut input: Box = match opt.file { None => { diff --git a/src/alphabet.rs b/src/alphabet.rs index f7cd819..efdc56e 100644 --- a/src/alphabet.rs +++ b/src/alphabet.rs @@ -38,17 +38,18 @@ const ALPHABET_SIZE: usize = 64; /// }; /// ``` /// -/// Building a lazy_static: +/// Building lazily: /// /// ``` /// use base64::{ /// alphabet::Alphabet, /// engine::{general_purpose::GeneralPurpose, GeneralPurposeConfig}, /// }; +/// use once_cell::sync::Lazy; /// -/// lazy_static::lazy_static! { -/// static ref CUSTOM: Alphabet = Alphabet::new("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/").unwrap(); -/// } +/// static CUSTOM: Lazy = Lazy::new(|| +/// Alphabet::new("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/").unwrap() +/// ); /// ``` #[derive(Clone, Debug, Eq, PartialEq)] pub struct Alphabet { From c8257a764d792213d3689dcbb87b7fe06bf40d35 Mon Sep 17 00:00:00 2001 From: Marshall Pierce <575695+marshallpierce@users.noreply.github.com> Date: Sat, 11 Nov 2023 07:47:38 -0700 Subject: [PATCH 2/3] Build tweaks - Update dev-dependencies MSRV to 1.70.0 - Run cargo update to avoid errors using a Cargo.lock from the CI cache --- .circleci/config.yml | 11 +++++++---- Cargo.toml | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 70eb080..4d2576d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -20,7 +20,7 @@ workflows: # get a nightly or stable toolchain via rustup instead of a mutable docker tag toolchain_override: [ '__msrv__', # won't add any other toolchains, just uses what's in the docker image - '1.65.0', # minimum needed to build dev-dependencies + '1.70.0', # minimum needed to build dev-dependencies 'stable', 'beta', 'nightly' @@ -50,6 +50,12 @@ jobs: - run: name: Log rustc version command: rustc --version + - run: + name: Build main target + # update first to select dependencies appropriate for this toolchain + command: | + cargo update + cargo build - run: name: Check formatting command: | @@ -64,9 +70,6 @@ jobs: rustup component add clippy cargo clippy --all-targets fi - - run: - name: Build main target - command: cargo build - run: name: Build all targets command: | diff --git a/Cargo.toml b/Cargo.toml index f768cc3..7a68073 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["base64", "utf8", "encode", "decode", "no_std"] categories = ["encoding"] license = "MIT OR Apache-2.0" edition = "2018" -# dev-dependencies require 1.65, but the main code doesn't +# dev-dependencies require 1.70, but the main code doesn't # This option was added in 1.56, keep it for when we bump MSRV. rust-version = "1.48.0" From 2f5d65b241647918664ba438bbd92ac6fd62cc73 Mon Sep 17 00:00:00 2001 From: Marshall Pierce <575695+marshallpierce@users.noreply.github.com> Date: Sat, 11 Nov 2023 08:20:10 -0700 Subject: [PATCH 3/3] Roll back dep updates Unfortunately we can't have nice things because of the people who want 1.48.0 compatibility. --- .circleci/config.yml | 2 +- Cargo.toml | 8 ++++---- examples/base64.rs | 21 +++++++++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4d2576d..ac0fae1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -20,7 +20,7 @@ workflows: # get a nightly or stable toolchain via rustup instead of a mutable docker tag toolchain_override: [ '__msrv__', # won't add any other toolchains, just uses what's in the docker image - '1.70.0', # minimum needed to build dev-dependencies + '1.65.0', # minimum needed to build dev-dependencies 'stable', 'beta', 'nightly' diff --git a/Cargo.toml b/Cargo.toml index 7a68073..36b0778 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["base64", "utf8", "encode", "decode", "no_std"] categories = ["encoding"] license = "MIT OR Apache-2.0" edition = "2018" -# dev-dependencies require 1.70, but the main code doesn't +# dev-dependencies require 1.65, but the main code doesn't # This option was added in 1.56, keep it for when we bump MSRV. rust-version = "1.48.0" @@ -35,11 +35,11 @@ required-features = ["alloc"] rustdoc-args = ["--generate-link-to-definition"] [dev-dependencies] -criterion = "0.5" +criterion = "0.4.0" rand = { version = "0.8.5", features = ["small_rng"] } -clap = { version = "4", features = ["derive"] } +structopt = "0.3.26" # test fixtures for engine tests -rstest = "0.18.0" +rstest = "0.13.0" rstest_reuse = "0.6.0" once_cell = "1" diff --git a/examples/base64.rs b/examples/base64.rs index d810243..0a214d2 100644 --- a/examples/base64.rs +++ b/examples/base64.rs @@ -5,15 +5,20 @@ use std::process; use std::str::FromStr; use base64::{alphabet, engine, read, write}; -use clap::{self, Parser}; +use structopt::StructOpt; -#[derive(Copy, Clone, Debug, Default, Parser)] +#[derive(Debug, StructOpt)] enum Alphabet { - #[default] Standard, UrlSafe, } +impl Default for Alphabet { + fn default() -> Self { + Self::Standard + } +} + impl FromStr for Alphabet { type Err = String; fn from_str(s: &str) -> Result { @@ -26,22 +31,22 @@ impl FromStr for Alphabet { } /// Base64 encode or decode FILE (or standard input), to standard output. -#[derive(Debug, Parser)] +#[derive(Debug, StructOpt)] struct Opt { /// decode data - #[arg(short, long)] + #[structopt(short = "d", long = "decode")] decode: bool, /// The alphabet to choose. Defaults to the standard base64 alphabet. /// Supported alphabets include "standard" and "urlsafe". - #[arg(short, long)] + #[structopt(long = "alphabet")] alphabet: Option, /// The file to encode/decode. - #[arg(short, long)] + #[structopt(parse(from_os_str))] file: Option, } fn main() { - let opt = Opt::parse(); + let opt = Opt::from_args(); let stdin; let mut input: Box = match opt.file { None => {