Make a code more generic and use object oriented programming
Closed this issue · 0 comments
matjazv commented
Description
Make a code more generic by using traits and implementing them on structs or types.
- currently some functions like
key_hash()
,value_hash()
, etc. are used only on&[u8]
object type - we may introduce a trait for those functions and implement it for an object type
- example: instead of a function call
key_hash(&value)
, we could call functionvalue.key_hash()
on an object - reference implementation:
pub trait MyHash {
fn my_hash(&self) -> Vec<u8>;
}
impl MyHash for &[u8] {
fn my_hash(&self) -> Vec<u8> {
let mut hasher = Sha256::new();
hasher.update(self);
let result = hasher.finalize();
return result.as_slice().to_vec();
}
}
Acceptance Criteria
- traits are used in a code
- methods are implemented for an objects where it makes sense
Additional Information
- only perform this action on a places in the code where and if it makes sense