Skip to content

Consider renaming BaseElement::as_int to BaseElement::to_u64 #387

@PhilippGackstatter

Description

@PhilippGackstatter

I never realized until recently that BaseElement::as_int is not actually a zero-cost operation, but actually does a non-zero-cost operation (montgomery reduction).

This is because the as_ prefix suggests that the cost of the operation is zero-cost, according to the widely used Rust naming conventions. This may seem like a small thing, but naming shapes the mental model and I was happily using as_int everywhere because I assumed it was zero-cost.

According to that guideline, this should instead use the to_ prefix. In that case we'd have to change the signature from &self to self to avoid triggering clippy::wrong_self_convention. That shouldn't affect the API, since BaseElement is Copy anyway.

If we rename this, I think it would be good to choose a more precise name as well and call it to_u64, because it returns a u64 whereas int suggests something more generic, but that's a small thing that just neatly fits into the larger issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions