One-shot APIs -- static functions vs methods
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 45/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Rust
- Stelle
- 25
- Fork
- 18
- Merge medio
- 16h 38m
- PR unite (30g)
- 3
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di bcgit/bc-rust
-
good first issue refactor
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
API Gap: KeyPairGenerator Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 58/100
Tutte le issue di bcgit/bc-rust
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
gitbutlerapp/gitbutler#15998 · 1 commento ·
-
bug triage:deciding
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
open-telemetry/otel-arrow#4132 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100