Skip to content
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
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion bsize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
6 changes: 4 additions & 2 deletions bsize/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn parse_size(mut src: &[u8]) -> Result<u64, ParseError> {
state = ParseState::Integer;
} else {
if *b >= b'5' {
mantissa += 1;
mantissa = mantissa.checked_add(1).ok_or(ParseError::Overflow)?;
}
state = ParseState::IntegerOverflow;
exponent += 1;
Expand All @@ -164,7 +164,7 @@ fn parse_size(mut src: &[u8]) -> Result<u64, ParseError> {
exponent -= 1;
} else {
if *b >= b'5' {
mantissa += 1;
mantissa = mantissa.checked_add(1).ok_or(ParseError::Overflow)?;
}
state = ParseState::FractionOverflow;
}
Expand Down Expand Up @@ -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",
Expand Down
17 changes: 14 additions & 3 deletions bsize/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<D>(de: D) -> Result<Self, D::Error>
Expand Down Expand Up @@ -100,15 +100,26 @@ macro_rules! impl_deserialize {
if de.is_human_readable() {
de.deserialize_any(Visitor)
} else {
de.deserialize_u64(Visitor)
de.$deserialize(Visitor)
}
}
}
)*
};
}

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 {
Expand Down
1 change: 1 addition & 0 deletions taplo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"]));
}
}

Expand Down