Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

One-shot APIs -- static functions vs methods

Open
#67 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
45/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Quiet
Tech stack
rust
Domain
api

Research direction

Start by inspecting the Hash trait and HashFactory, then search the repository for other traits using the ::new().hash(..) pattern. Determine whether the factory can support static ::hash(..) calls while remaining dyn-compatible; if not, apply the proposed dual-method approach. Done means similar patterns are cleaned up and crate documentation uses the static form.

Written by the indexing model from the issue text.

Description

Consider:

let output: Vec<u8> = sha3::SHA3_256::new().hash(data);

The pattern of ::new().hash(..), where .hash(..) is a method, is a code smell since should really be a static function ::hash(..). The reason why it's like that is because the HashFactory requires the Hash trait to be dyn-compatible, and I was not able to get the factory to work with a static ::hash(..).

The task for this ticket is to play some more with whether it's possible to get the HashFactory to chain properly to a ::hash(..). If not, @npajkovsky suggested that we could cheat and simply have the Hash trait have both versions:

trait Hash {
  fn hash(data: &[u8]) -> Vec<u8> {
    Self::new().hash_method(data)
  };

  fn hash_method(self, data: &[u8]) -> Vec<u8>;
}

and then we continue to use the .hash_method(data) version within the HashFactory, but we can simplify the sample code in the crate docs to use the cleaner SHA256::hash(data) version.

Note: I'm using Hash as an example, but this smelly pattern exists across other traits as well. This ticket should clean up all similar patterns.

Dominant language
Rust
Stars
25
Forks
18
Avg merge
14d 10h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bcgit/bc-rust

All issues in bcgit/bc-rust

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.