Skip to content

Idea: Pow trait #38

Closed
Closed
@clarfonthey

Description

@clarfonthey

I've been working on a crate which works with runtime-level units, and I think that having a generic Pow trait would be useful.

Essentially, it would be very similar to the other unary op traits, namely:

pub trait Pow<RHS> {
    type Output;
    fn pow(self, rhs: RHS) -> Self::Output;
}

And in most cases, this would simply do exponentiation by squaring as included in the existing pow functions. However, it may be easier to implement for some types, namely a unit could simply multiply a field that indicates what power of the given unit you have. Another example is that a type which constrains which values it has, e.g. a matrix which specifically performs scaling operations, could be modified to do less work.

This would be weird to implement and may cause confusion with the existing pow function, which is why I haven't offered a PR for it. But it might be nice to have in this crate.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions