Expand description
UCUM Core Library – Rust 2024 Edition
This crate provides parsing, validation and conversion utilities for the
Unified Code for Units of Measure (UCUM). It aims to be no_std-optional
and suitable for both embedded and server environments.
Re-exports§
pub use crate::performance::CacheStats;pub use crate::performance::EvaluationCache;pub use crate::performance::find_unit_optimized;pub use crate::performance::find_prefix_optimized;pub use crate::performance::get_cache_stats;pub use crate::performance::clear_global_cache;pub use crate::performance::get_cache_sizes;pub use crate::performance::with_global_cache;pub use crate::performance::find_prefixes_with_trie;pub use crate::performance::find_longest_prefix_with_trie;pub use crate::special_units::ArbitraryHandler;pub use crate::special_units::ConversionContext;pub use crate::special_units::LogarithmicHandler;pub use crate::special_units::SpecialUnitHandler;pub use crate::special_units::SpecialUnitRegistry;pub use crate::special_units::TemperatureHandler;pub use crate::suggestions::SuggestionEngine;
Modules§
- performance
- Performance optimization module for Performance and Scalability
- precision
- Precision arithmetic support for UCUM calculations.
- special_
units - Special unit handlers for extensible UCUM special unit processing.
- suggestions
- Suggestion engine for error corrections and unit alternatives (Phase 5).
Structs§
- Advanced
Conversion Context - Advanced conversion context for enhanced conversion operations.
- Advanced
Conversion Result - Result of an advanced conversion operation with metadata.
- Base
Unit - Base unit record (e.g. metre, second, kelvin).
- Canonical
Unit - Canonical unit representation
- Derived
Unit - Derived or custom unit that resolves to a base vector plus factor/offset.
- Dimension
- Dimensional vector (M, L, T, I, Θ, N, J) per UCUM spec.
- Eval
Result - Result returned by
evaluate()– canonical factor, dimension vector, offset. - Measurement
Context - Measurement context providing domain-specific preferences and requirements.
- Precision
Requirements - Precision requirements for different domains.
- Prefix
- SI prefix such as
k(kilo) orm(milli). - Quantity
- Numerical quantity paired with a unit expression.
- Span
- Source location information for parser errors
- Ucum
Error - Enhanced UCUM error with detailed context and suggestions
- Ucum
Model - UCUM model information and metadata.
- Unit
Analysis - Detailed analysis result for a UCUM expression.
- Unit
Arithmetic Result - Result of unit arithmetic operations
- Unit
Factor - A base expression accompanied by an integer exponent (default 1).
- Unit
Record - Unit
Result - Result of mathematical operations with units
Enums§
- Concept
Kind - Concept kinds for filtering search results.
- Decimal
Precision - Decimal precision configuration.
- Domain
- Domain-specific context for measurements.
- Error
Kind - Specific error kinds with detailed context
- Rounding
Mode - Rounding mode for conversions.
- Temperature
Scale - Temperature scale preference.
- Unit
Expr - A fully parsed UCUM expression.
Functions§
- analyse
- Analyse a UCUM expression and return detailed information about it.
- canonicalize_
expression - Convert a unit expression to its canonical (base units) form.
- convert_
with_ context - Convert with advanced context and precision control.
- divide_
by - Divide two quantities with units.
- eval
- Evaluate a parsed
UnitExprinto canonical factor, dimension and offset. Uses enhanced caching to avoid re-computing the same expressions. - evaluate
- Evaluate a parsed
UnitExprinto canonical factor, dimension and offset. Uses enhanced caching to avoid re-computing the same expressions. - find_
prefix - Lookup a prefix by symbol.
- find_
unit - Lookup a unit by code using the generated registry.
- generate_
display_ name - Generate a human-readable display name for a UCUM expression.
- get_
all_ units - Get all units from the registry.
- get_
canonical_ units - Get the canonical units for a given UCUM expression.
- get_
common_ display - Get a human-readable display name for a unit code.
- get_
defined_ forms - Get all defined forms of a unit code.
- get_
model - Get the UCUM model information.
- get_
properties - Get all available properties in the UCUM model.
- is_
comparable - Check if two units are commensurable (can be converted between each other).
- multiply
- Multiply two quantities with units.
- optimize_
expression - Optimize a unit expression for better readability and canonical form.
- parse_
expression - Parse a UCUM expression string into a
UnitExprAST. - search_
units - Search for units by name, code, or display name.
- search_
units_ by_ property - Search for units by property (e.g., “length”, “mass”, “time”).
- search_
units_ filtered - Search for units with concept kind filtering.
- search_
units_ fuzzy - Search for units using fuzzy matching.
- search_
units_ regex - Search for units using regular expressions.
- simplify_
expression - Simplify a unit expression by combining like terms and reducing complexity.
- unit_
divide - Divide one unit expression by another.
- unit_
multiply - Multiply two unit expressions together.
- validate
- Validate a UCUM expression string.
- validate_
canonical_ units - Validate that canonical units match the expected form.
- validate_
in_ property - Validate that a unit expression is appropriate for a given property.
- validate_
ucum - Validate the UCUM implementation for self-consistency.