diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0e764e..67c70f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,18 +82,43 @@ jobs: run: cargo x test --no-capture shell: bash + no_std: + name: Check no_std + needs: msrv + strategy: + matrix: + rust-version: ${{ fromJson(needs.msrv.outputs.rust-versions) }} + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v6 + - uses: Swatinem/rust-cache@v2 + - name: Delete rust-toolchain.toml + run: rm rust-toolchain.toml + - name: Install toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust-version }} + targets: thumbv7em-none-eabihf + - name: Check no_std + run: | + cargo check -p bsize --no-default-features --target thumbv7em-none-eabihf + cargo check -p bsize --all-features --target thumbv7em-none-eabihf + shell: bash + required: name: Required runs-on: ubuntu-24.04 if: ${{ always() }} needs: - check + - no_std - test steps: - name: Guardian run: | if [[ ! ( \ "${{ needs.check.result }}" == "success" \ + && "${{ needs.no_std.result }}" == "success" \ && "${{ needs.test.result }}" == "success" \ ) ]]; then echo "Required jobs haven't been completed successfully." diff --git a/bsize/Cargo.toml b/bsize/Cargo.toml index 888e9f7..53236da 100644 --- a/bsize/Cargo.toml +++ b/bsize/Cargo.toml @@ -37,7 +37,7 @@ default = [] serde = ["dep:serde_core"] [dependencies] -serde_core = { version = "1", optional = true } +serde_core = { version = "1", default-features = false, optional = true } [dev-dependencies] serde = { version = "1", features = ["derive"] } diff --git a/bsize/src/parse.rs b/bsize/src/parse.rs index 6f95bd9..c47a2b5 100644 --- a/bsize/src/parse.rs +++ b/bsize/src/parse.rs @@ -149,7 +149,7 @@ fn parse_size(mut src: &[u8]) -> Result { state = ParseState::Integer; } else { if *b >= b'5' { - mantissa += 1; + mantissa = mantissa.checked_add(1).ok_or(ParseError::Overflow)?; } state = ParseState::IntegerOverflow; exponent += 1; @@ -164,7 +164,7 @@ fn parse_size(mut src: &[u8]) -> Result { exponent -= 1; } else { if *b >= b'5' { - mantissa += 1; + mantissa = mantissa.checked_add(1).ok_or(ParseError::Overflow)?; } state = ParseState::FractionOverflow; } @@ -307,6 +307,8 @@ mod tests { for input in [ "18_446_744_073_709_551_616", "18_446_744_073_709_551_620", + "18446744073709551615.5", + "184467440737095516155", "18.446_744_073_709_551_616 EB", "19EB", "16EiB", diff --git a/bsize/src/serde.rs b/bsize/src/serde.rs index 1034c3c..bccc4c7 100644 --- a/bsize/src/serde.rs +++ b/bsize/src/serde.rs @@ -40,7 +40,7 @@ macro_rules! impl_serialize { impl_serialize!(u8, u16, u32, u64, usize); macro_rules! impl_deserialize { - ($($ty:ty),* $(,)?) => { + ($($ty:ty => $deserialize:ident),* $(,)?) => { $( impl<'de> serde_core::Deserialize<'de> for BSize<$ty> { fn deserialize(de: D) -> Result @@ -100,7 +100,7 @@ macro_rules! impl_deserialize { if de.is_human_readable() { de.deserialize_any(Visitor) } else { - de.deserialize_u64(Visitor) + de.$deserialize(Visitor) } } } @@ -108,7 +108,18 @@ macro_rules! impl_deserialize { }; } -impl_deserialize!(u8, u16, u32, u64, usize); +impl_deserialize!( + u8 => deserialize_u8, + u16 => deserialize_u16, + u32 => deserialize_u32, + u64 => deserialize_u64, +); + +#[cfg(target_pointer_width = "32")] +impl_deserialize!(usize => deserialize_u32); + +#[cfg(target_pointer_width = "64")] +impl_deserialize!(usize => deserialize_u64); #[cfg(test)] mod tests { diff --git a/taplo.toml b/taplo.toml index 1cb0f3a..ebbb309 100644 --- a/taplo.toml +++ b/taplo.toml @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +exclude = ["target/**"] include = ["Cargo.toml", "**/*.toml"] [formatting] diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 94004b9..937be94 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! An xtask binary for managing workspace tasks. +//! A binary for managing workspace tasks. use std::path::Path; use std::process::Command as StdCommand; @@ -71,6 +71,7 @@ struct CommandTest { impl CommandTest { fn run(self) { run_command(make_test_cmd(self.no_capture, &[])); + run_command(make_test_cmd(self.no_capture, &["serde"])); } }