pub fn to(measure: f64, source_unit: &Unit, dest_unit: &Unit) -> Result<f64, String> {
        let energy_order = [Unit::Joule, Unit::MilliJoule, Unit::MicroJoule];
        let power_order = [
            Unit::MegaWatt,
            Unit::KiloWatt,
            Unit::Watt,
            Unit::MilliWatt,
            Unit::MicroWatt,
        ];
        let pos_source_energy = energy_order.iter().position(|x| x == source_unit);
        let pos_dest_energy = energy_order.iter().position(|x| x == dest_unit);
        let pos_source_power = power_order.iter().position(|x| x == source_unit);
        let pos_dest_power = power_order.iter().position(|x| x == dest_unit);
        if let (Some(pos_source), Some(pos_dest)) = (pos_source_energy, pos_dest_energy) {
            Ok(measure * Unit::get_mult(pos_source, pos_dest))
        } else if let (Some(pos_source), Some(pos_dest)) = (pos_source_power, pos_dest_power) {
            Ok(measure * Unit::get_mult(pos_source, pos_dest))
        } else {
            panic!("Impossible conversion asked from energy value to power value (without time dimension).");
        }
    }
/// Converts either an energy measurement (Joule, MilliJoule or MicroJoule) to another energy Unit (Joule, MilliJoule or MicroJoule)
/// or a power measurement (MilliWatt, MicroWatt, Watt, KiloWatt) to another power Unit
Converts either an energy measurement (Joule, MilliJoule or MicroJoule) to another energy Unit (Joule, MilliJoule or MicroJoule)
or a power measurement (MilliWatt, MicroWatt, Watt, KiloWatt) to another power Unit
Converts either an energy measurement ( Joule MilliJoule or MicroJoule ) to another energy Unit ( Joule MilliJoule or MicroJoule ) or a power measurement ( MilliWatt MicroWatt Watt KiloWatt ) to another power Unit
pub fn to(measure: f64, source_unit: &Unit, dest_unit: &Unit) -> Result<f64, String> {
        let energy_order = [Unit::Joule, Unit::MilliJoule, Unit::MicroJoule];
        let power_order = [
            Unit::MegaWatt,
            Unit::KiloWatt,
            Unit::Watt,
            Unit::MilliWatt,
            Unit::MicroWatt,
        ];
        let pos_source_energy = energy_order.iter().position(|x| x == source_unit);
        let pos_dest_energy = energy_order.iter().position(|x| x == dest_unit);
        let pos_source_power = power_order.iter().position(|x| x == source_unit);
        let pos_dest_power = power_order.iter().position(|x| x == dest_unit);
        if let (Some(pos_source), Some(pos_dest)) = (pos_source_energy, pos_dest_energy) {
            Ok(measure * Unit::get_mult(pos_source, pos_dest))
        } else if let (Some(pos_source), Some(pos_dest)) = (pos_source_power, pos_dest_power) {
            Ok(measure * Unit::get_mult(pos_source, pos_dest))
        } else {
            panic!("Impossible conversion asked from energy value to power value (without time dimension).");
        }
    }
pub fn to ( measure : f64 , source_unit : & Unit , dest_unit : & Unit ) -> Result < f64 , String > { let energy_order = [ Unit :: Joule , Unit :: MilliJoule , Unit :: MicroJoule ] ; let power_order = [ Unit :: MegaWatt , Unit :: KiloWatt , Unit :: Watt , Unit :: MilliWatt , Unit :: MicroWatt , ] ; let pos_source_energy = energy_order . iter ( ) . position ( | x | x == source_unit ) ; let pos_dest_energy = energy_order . iter ( ) . position ( | x | x == dest_unit ) ; let pos_source_power = power_order . iter ( ) . position ( | x | x == source_unit ) ; let pos_dest_power = power_order . iter ( ) . position ( | x | x == dest_unit ) ; if let ( Some ( pos_source ) , Some ( pos_dest ) ) = ( pos_source_energy , pos_dest_energy ) { Ok ( measure * Unit :: get_mult ( pos_source , pos_dest ) ) } else if let ( Some ( pos_source ) , Some ( pos_dest ) ) = ( pos_source_power , pos_dest_power ) { Ok ( measure * Unit :: get_mult ( pos_source , pos_dest ) ) } else { panic ! ( " " ) ; } }
Converts either an energy measurement (Joule, MilliJoule or MicroJoule) to another energy Unit (Joule, MilliJoule or MicroJoule)
or a power measurement (MilliWatt, MicroWatt, Watt, KiloWatt) to another power Unit
Converts either an energy measurement ( Joule MilliJoule or MicroJoule ) to another energy Unit ( Joule MilliJoule or MicroJoule ) or a power measurement ( MilliWatt MicroWatt Watt KiloWatt ) to another power Unit
measure
f64
source_unit
&Unit
dest_unit
&Unit
measure
f64
source_unit
&Unit
dest_unit
&Unit