fix: consistent American spelling used through out #986
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 comprehensive implementation of metric length unit conversion to the conversions module. The implementation supports conversions between nine metric length units ranging from meters to yottameters ($10^{24}$ meters).
Spelling Convention: This implementation uses American spellings (meter, kilometer, megameter, etc.) officially in all enum variants and documentation, following standard programming conventions and SI guidelines. However, the parser accepts both American AND British spellings for maximum compatibility and user-friendliness.
Implementation Details
The implementation provides:
MetricLengthUnitenum - Type-safe representation of length units (using American spellings)convert_metric_length(value: f64, from: MetricLengthUnit, to: MetricLengthUnit) -> f64metric_length_conversion(value: f64, from_type: &str, to_type: &str) -> Result<f64, String>Algorithm Details
The conversion uses the formula:
Where each unit has an exponent representing its power of 10 relative to meters.
Example:
Time Complexity:$O(1)$ - constant time conversion$O(1)$ - no additional space needed
Space Complexity:
Design Choices
convert_metric_length) and string-based (metric_length_conversion) functionsFromStrimplementation accepts both American ("meter") and British ("metre") spellingsResulttype for proper Rust error handlinglength_conversionmoduleWhy American Spellings?
Changes Made
src/conversions/order_of_magnitude_conversion.rswith complete implementationsrc/conversions/mod.rsto include and export the moduleType of Change
Testing
All tests pass successfully:
Test Coverage
✅ 40+ Unit Tests Including:
Examples
Checklist
cargo fmtcargo clippyAdditional Context
This implementation is based on the Python version from TheAlgorithms/Python and follows Rust best practices:
Improvements over Python version:
Resulttype,FromStrtrait, pattern matching, and Rust conventions{}in stringsStandards Compliance:
Spelling Policy:
References