Skip to content

Add/replace methods to be more Rust idiomatic #155

Closed
@cjordan

Description

@cjordan

Hi,

You asked for some suggestions on how to improve hifitime; I've found a couple!

The Rust API Guidelines provide some "rules" on how to name methods, whether into_, to_ or as_. Just now as I was poking some code, I realised that hifitime::Duration doesn't really follow this, and I think it would make the API better or at least more consistent with existing Rust APIs (e.g. Duration::in_seconds should be Duration::to_seconds). Another bugbear of mine is Duration::from_f64; this method could remain, but I think it would be nicer to use Duration::from_secs, Duration::from_millis etc., which is very similar to the standard library functions.

hifitime::Epoch technically is correct with its many as_ methods, although these methods borrow self when Epoch is already Copy (i.e. these methods don't need to borrow, and given the guidelines these methods should instead be named to_).

The #[deprecated = reason] annotation can be used to maintain semver compatibility while introducing any new methods.

What do you think? It would be a decent amount of work to vet all existing methods, but I think it would be worth it. There is no rush on this work as it's mostly a matter of taste, and I would be happy to pitch in but I'm likely too busy until early next year.

Once again, thanks for your help with this great library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions