44
55pub mod unit;
66pub mod unit_dimension;
7- #[ cfg( feature = "units" ) ]
7+ #[ cfg( feature = "units-db " ) ]
88pub mod units_generated;
9+ use lazy_static:: lazy_static;
910
1011pub use unit:: Unit ;
1112pub use unit_dimension:: UnitDimensions ;
1213
1314/// Get unit by name, if it is defined in the units database
1415#[ allow( unused_variables) ]
1516pub fn get_unit ( unit : & str ) -> Option < & ' static Unit > {
16- #[ cfg( feature = "units" ) ]
17+ #[ cfg( feature = "units-db " ) ]
1718 {
1819 return units_generated:: UNITS . get ( unit) . copied ( ) ;
1920 }
20- #[ cfg( not( feature = "units" ) ) ]
21+ #[ cfg( not( feature = "units-db " ) ) ]
2122 return None ;
2223}
2324
2425/// Tries to get the unit by name, if none is found, return a default unit
2526pub fn get_unit_or_default ( unit : & str ) -> & ' static Unit {
26- if let Some ( unit) = get_unit ( unit) {
27- unit
28- } else {
29- & * DEFAULT_UNIT
30- }
27+ get_unit ( unit) . unwrap_or ( & * DEFAULT_UNIT )
3128}
3229
3330/// Match units for the dimension
3431#[ allow( unused_variables) ]
3532pub fn match_units ( dim : UnitDimensions , scale : f64 ) -> Vec < & ' static Unit > {
36- #[ cfg( feature = "units" ) ]
33+ #[ cfg( feature = "units-db " ) ]
3734 {
3835 units_generated:: UNITS
3936 . iter ( )
@@ -46,11 +43,11 @@ pub fn match_units(dim: UnitDimensions, scale: f64) -> Vec<&'static Unit> {
4643 } )
4744 . collect ( )
4845 }
49- #[ cfg( not( feature = "units" ) ) ]
46+ #[ cfg( not( feature = "units-db " ) ) ]
5047 return Vec :: default ( ) ;
5148}
5249
53- #[ cfg( feature = "units" ) ]
50+ #[ cfg( feature = "units-db " ) ]
5451fn approx_eq ( a : f64 , b : f64 ) -> bool {
5552 if a == b {
5653 return true ;
0 commit comments