feat: add comprehensive weight unit conversion module #1012
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 weight conversion module to the conversions directory, providing support for 23 different weight units across metric, imperial, troy, and scientific measurement systems.
What's New
Units Added (23 Total)
Large Metric Units:
Standard Metric Units:
Imperial/US Large Units:
Imperial/US Common Units:
Troy Weight System:
Other Units:
Features
✅ Type-safe conversions using Rust enums
✅ String-based conversions for convenience
✅ Flexible API supporting both
WeightUnitenums and string identifiers✅ Comprehensive aliases (e.g., "kg", "lb", "oz", "μg", "ozt")
✅ Extensive test coverage with 100+ test cases
✅ Full documentation with usage examples and references
✅ Zero dependencies beyond std library
✅ High precision conversions based on official standards
Usage Examples
Type-Safe Conversion
String-Based Conversion
Mixed Usage
Testing
All tests pass with comprehensive coverage:
cargo test weightTest Coverage:
Implementation Details
The module follows the same pattern as the existing
pressure.rsmodule:IntoWeightUnittrait for polymorphismReferences
All conversion factors are sourced from official references:
Checklist
cargo fmtsrc/conversions/mod.rs