I am trying to select a digest algorithm (from rust-crypto) based on the configuration line. In Python or JavaScript, let's say I would use reflection to understand:
getattr(Digest, myAlgorithm)
... but from the fact that I was able to Google, this is not the best practice in a language such as Rust (plus I have not found any details on how to do this). My initial thought was to use pattern matching:
let mut digest = match myAlgorithm { "sha256" => Sha256::new(), ... };
However, this does not work, because although all branches of the correspondence implement the same attribute, they are ultimately different types. Moreover, assuming that there is a way around this, itβs a lot of hassle to manually list all of these parameters in the code.
What is the right way to do this in Rust?
source share