feat: add speed conversion module #998
Merged
+233
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a new module for converting between different speed units (km/h, m/s, mph, knots, ft/s, Mach, and speed of light).
Features Added
convert_speed: Convert speed values between any two supported unitsSpeedUnitenum for type-safe speed unit representationType of Change
✅ New algorithm/data structure
✅ Documentation
✅ Tests
Testing
All tests pass:
cargo test conversions::speedResults:
Algorithm Complexity
Implementation Details
Conversion Algorithm
Uses kilometers per hour (km/h) as the base unit for all conversions:
Speed Unit Values
All conversions use these standardized conversion factors:
To km/h (multiply by):
From km/h (multiply by):
Enum-Based Design
SpeedUnitenum instead of string dictionaries for type safetyCopy,Clone,Debug,PartialEqtraitsDisplaytrait for user-friendly unit namesas_kmh_multiplier(),kmh_multiplier()) for conversion logicType Safety Benefits
References
Checklist
✅ Code follows Rust idioms and best practices
✅ Self-documenting code with comprehensive doc comments
✅ All functions have doc comments
✅ Tests cover normal cases and edge cases
✅ Code compiles without warnings (
clippyclean)✅ All tests pass
✅ Proper use of type-safe enum (
SpeedUnit)✅ Module properly integrated into
src/conversions/mod.rs✅ No external dependencies beyond
stdExample Usage
Additional Notes