Skip to content

How to raise a Quantity to a power? #267

@blaine-dodson

Description

@blaine-dodson

As for example, finding an area:

extern crate uom;

use uom::si::f32::Length;
use uom::si::length::kilometer;

fn main() {
	let l = Length::new::<kilometer>(5.0);
	let area = l.powi(2);
	println!("The area is {:?}", area);
}

Fails to compile with:

error[E0277]: cannot multiply `PInt<UInt<UTerm, B1>>` by `{integer}`
 --> src\main.rs:8:15
  |
8 |     let area = l.powi(2);
  |                  ^^^^ no implementation for `PInt<UInt<UTerm, B1>> * {integer}`
  |
  = help: the trait `std::ops::Mul<{integer}>` is not implemented for `PInt<UInt<UTerm, B1>>`

error[E0277]: the trait bound `{integer}: Integer` is not satisfied
 --> src\main.rs:8:20
  |
8 |     let area = l.powi(2);
  |                       ^ the trait `Integer` is not implemented for `{integer}`
  |
  = help: the following implementations were found:
            <NInt<U> as Integer>
            <PInt<U> as Integer>
            <Z0 as Integer>

Is this possible? If so, is the correct way to do it documented somewhere? How can I know which operations, say from here, can be applied to a Quantity, and which cannot?

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