Skip to content

Unit request: LinearEnergyDensity #501

@Titaniumtown

Description

@Titaniumtown

I mentioned in this issue: #357 (comment) my need for a LinearEnergyDensity type. My use case would include a wh/mi representation and such. Can anyone guide me through how to create such a unit? I'm a bit lost. Thanks!

I created this as a stop-gap:

pub struct LinearEnergyDensity<T: uom::si::length::Conversion<f32>> {
    energy: Energy,
    _base_unit: T,
}

impl<T: uom::si::length::Conversion<f32>> LinearEnergyDensity<T> {
    pub const fn new(energy: Energy, base_unit: T) -> Self {
        Self {
            energy,
            _base_unit: base_unit,
        }
    }
}

impl<T: uom::si::length::Conversion<f32>> Mul<Length> for LinearEnergyDensity<T> {
    type Output = Energy;

    fn mul(self, rhs: Length) -> Self::Output {
        let conv_length = rhs.get::<T>();
        self.energy * conv_length
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions