Skip to content

A couple of small fixes for unit types#654

Merged
alexdewar merged 2 commits intomainfrom
unit-type-fixes
Jun 23, 2025
Merged

A couple of small fixes for unit types#654
alexdewar merged 2 commits intomainfrom
unit-type-fixes

Conversation

@alexdewar
Copy link
Copy Markdown
Collaborator

Description

I was fiddling with unit types on another branch and noticed a couple of small problems:

  1. A unit type U divided by U should yield Dimensionless, not U
  2. We should pass self by ref (&self) not value (self) for various methods of unit types, otherwise it'll be consumed when they're run

Type of change

  • Bug fix (non-breaking change to fix an issue)
  • New feature (non-breaking change to add functionality)
  • Refactoring (non-breaking, non-functional change to improve maintainability)
  • Optimization (non-breaking change to speed up the code)
  • Breaking change (whatever its nature)
  • Documentation (improve or add documentation)

Key checklist

  • All tests pass: $ cargo test
  • The documentation builds and looks OK: $ cargo doc

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

If we use `self`, without the ampersand, then calling the method will consume the struct (like moving it) and it won't be usable again.
@alexdewar alexdewar requested review from Copilot and tsmbland June 23, 2025 16:22
@alexdewar alexdewar added the bug Something isn't working label Jun 23, 2025
@alexdewar alexdewar added this to MUSE Jun 23, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes issues with unit types by updating the division operator to return a Dimensionless type and modifying methods to take self by reference instead of by value.

  • Update division operator to yield Dimensionless
  • Change method signatures (value, is_normal, is_finite, abs) to use &self

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.43%. Comparing base (f6ff308) to head (86791a4).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #654   +/-   ##
=======================================
  Coverage   88.43%   88.43%           
=======================================
  Files          39       39           
  Lines        3555     3555           
  Branches     3555     3555           
=======================================
  Hits         3144     3144           
  Misses        219      219           
  Partials      192      192           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tsmbland
Copy link
Copy Markdown
Collaborator

  1. A unit type U divided by U should yield Dimensionless, not U

Silly me 🤦

@alexdewar alexdewar merged commit 701a96c into main Jun 23, 2025
7 checks passed
@alexdewar alexdewar deleted the unit-type-fixes branch June 23, 2025 16:34
@github-project-automation github-project-automation Bot moved this to ✅ Done in MUSE Jun 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants