diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..9c60153 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,13 @@ +version: 2 +updates: + - package-ecosystem: cargo + directory: / + schedule: + interval: daily + ignore: + - dependency-name: "*" + # patch and minor updates don't matter for libraries + # remove this ignore rule if your package has binaries + update-types: + - "version-update:semver-patch" + - "version-update:semver-minor" diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..61a91db --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,75 @@ +on: + push: + branches: [master] + pull_request: +name: check +jobs: + clippy: + runs-on: ${{ matrix.os }} + name: clippy / ${{ matrix.os }} / stable + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + default: true + components: clippy + - name: cargo clippy --all-features --all-targets --tests --workspace -- -D warnings + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-features --all-targets --tests --workspace -- -D warnings + doc: + runs-on: ${{ matrix.os }} + name: doc / ${{ matrix.os }} / stable + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + default: true + - name: cargo doc --all-features --no-deps + uses: actions-rs/cargo@v1 + with: + command: doc + args: --all-features --no-deps + env: + RUSTDOCFLAGS: --cfg docsrs + fmt: + runs-on: ${{ matrix.os }} + name: fmt / ${{ matrix.os }} / stable + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + components: rustfmt + - name: cargo fmt --all --check + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all --check diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7a52478 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,108 @@ +on: + push: + branches: [master] + pull_request: +name: test +jobs: + test: + runs-on: ${{ matrix.os }} + name: ${{ matrix.os }} / stable + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + - name: cargo install cargo-hack + uses: taiki-e/install-action@cargo-hack + - name: cargo generate-lockfile --manifest-path num-format/Cargo.toml + if: hashFiles('Cargo.lock') == '' + uses: actions-rs/cargo@v1 + with: + command: generate-lockfile + - name: cargo hack --package num-format --feature-powerset test --locked + uses: actions-rs/cargo@v1 + with: + command: hack + args: --package num-format --feature-powerset test --locked + - name: cargo hack --package num-format-benches --feature-powerset test --locked + uses: actions-rs/cargo@v1 + with: + command: hack + args: --package num-format-benches --feature-powerset test --locked + - name: cargo hack --package num-format-dev --feature-powerset test --locked + uses: actions-rs/cargo@v1 + with: + command: hack + args: --package num-format-dev --feature-powerset test --locked + test-msrv: + runs-on: ${{ matrix.os }} + name: ${{ matrix.os }} / ${{ matrix.msrv }} + # we use a matrix here just because env can't be used in job names + # https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability + strategy: + fail-fast: false + matrix: + msrv: [1.58.0] + os: [macos-latest, ubuntu-latest, windows-latest] + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install ${{ matrix.msrv }} + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.msrv }} + default: true + - name: cargo install cargo-hack + uses: taiki-e/install-action@cargo-hack + - name: cargo generate-lockfile --manifest-path num-format/Cargo.toml + if: hashFiles('Cargo.lock') == '' + uses: actions-rs/cargo@v1 + with: + command: generate-lockfile + args: --manifest-path num-format/Cargo.toml + - name: cargo hack --package num-format --feature-powerset test --locked + uses: actions-rs/cargo@v1 + with: + command: hack + args: --package num-format --feature-powerset test --locked + test-msrv-no-default-features: + runs-on: ${{ matrix.os }} + name: ${{ matrix.os }} / ${{ matrix.msrv }} + # we use a matrix here just because env can't be used in job names + # https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability + strategy: + fail-fast: false + matrix: + msrv: [1.56.0] + os: [macos-latest, ubuntu-latest, windows-latest] + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install ${{ matrix.msrv }} + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.msrv }} + default: true + - name: cargo generate-lockfile --manifest-path num-format/Cargo.toml + if: hashFiles('Cargo.lock') == '' + uses: actions-rs/cargo@v1 + with: + command: generate-lockfile + args: --manifest-path num-format/Cargo.toml + - name: cargo test --package num-format --no-default-features --locked + uses: actions-rs/cargo@v1 + with: + command: test + args: --package num-format --no-default-features --locked diff --git a/num-format/src/impls/num.rs b/num-format/src/impls/num.rs index 2ae9d6d..568b103 100644 --- a/num-format/src/impls/num.rs +++ b/num-format/src/impls/num.rs @@ -126,8 +126,7 @@ where let mut bytes_written = 0; let mut digits_remaining = s.len(); - let mut iter = s.as_bytes().iter(); - while let Some(digit) = iter.next() { + for digit in s.as_bytes().iter() { if bytes_written == sep_next { w.write_all(sep_bytes)?; bytes_written += sep_len; @@ -188,8 +187,7 @@ where let mut bytes_written = 0; let mut chars_written = 0; let mut digits_remaining = s.len(); - let mut iter = s.chars(); - while let Some(c) = iter.next() { + for c in s.chars() { if chars_written == sep_next { w.write_str(separator)?; bytes_written += sep_len; diff --git a/num-format/src/system_locale/nix/encoding.rs b/num-format/src/system_locale/nix/encoding.rs index 01fc380..644a11d 100644 --- a/num-format/src/system_locale/nix/encoding.rs +++ b/num-format/src/system_locale/nix/encoding.rs @@ -7,13 +7,13 @@ lazy_static! { } // See https://docs.rs/encoding_rs/0.8.16/encoding_rs/ -static LATIN_1: &'static encoding_rs::Encoding = encoding_rs::WINDOWS_1252; +static LATIN_1: &encoding_rs::Encoding = encoding_rs::WINDOWS_1252; #[derive(Copy, Clone, Debug)] pub(crate) struct Encoding(&'static encoding_rs::Encoding); impl Encoding { - pub(crate) fn decode<'a>(&self, bytes: &'a [u8]) -> Result { + pub(crate) fn decode(&self, bytes: &[u8]) -> Result { let (cow, _encoding, is_err) = self.0.decode(bytes); if is_err { return Err(Error::system_invalid_return( diff --git a/num-format/src/system_locale/windows.rs b/num-format/src/system_locale/windows.rs index 0bde345..5097246 100644 --- a/num-format/src/system_locale/windows.rs +++ b/num-format/src/system_locale/windows.rs @@ -249,7 +249,7 @@ fn enum_system_locales_ex() -> Result, Error> { Err(_) => return CONTINUE, }; - if &s == "" { + if s.is_empty() { return CONTINUE; } @@ -300,6 +300,7 @@ fn get_locale_info_ex(locale_name: &str, request: Request) -> Result Result { let size = unsafe { winnls::GetLocaleInfoEx(lpLocaleName, LCType, buf_ptr, size) }; + #[allow(clippy::comparison_chain)] if size == 0 { let err = unsafe { GetLastError() }; if err == 87 {