refactor persistency
This commit is contained in:
@ -11,7 +11,7 @@ pub use sha256::Sha256;
|
||||
mod texture_format;
|
||||
pub use texture_format::TextureFormat;
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Serialize, Deserialize, Debug)]
|
||||
#[derive(Eq, PartialEq, Clone, Serialize, Deserialize, Debug, Hash)]
|
||||
pub struct Texture {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
|
@ -14,9 +14,25 @@ fn hash_to_hex_string(hash: &[u8; 32]) -> String {
|
||||
}
|
||||
|
||||
impl Sha256 {
|
||||
pub fn create_hex_string(&self) -> String {
|
||||
pub fn as_hex_string(&self) -> String {
|
||||
hash_to_hex_string(&self.0)
|
||||
}
|
||||
|
||||
pub fn from_data(data: &[u8]) -> Self {
|
||||
use sha2::Digest;
|
||||
|
||||
let mut hasher = sha2::Sha256::new();
|
||||
hasher.input(data);
|
||||
|
||||
let hash_result = hasher.result();
|
||||
|
||||
let mut hash_arr = [0u8; 32];
|
||||
for i in 0..32 {
|
||||
hash_arr[i] = hash_result[i];
|
||||
}
|
||||
|
||||
Sha256(hash_arr)
|
||||
}
|
||||
}
|
||||
|
||||
fn as_hex<S>(hash: &[u8; 32], serializer: S) -> Result<S::Ok, S::Error>
|
||||
|
@ -8,6 +8,12 @@ pub enum TextureFormat {
|
||||
JPEG,
|
||||
}
|
||||
|
||||
impl TextureFormat {
|
||||
fn variants() -> &'static [TextureFormat] {
|
||||
&[TextureFormat::PNG, TextureFormat::JPEG]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// Lol, I thought we would need custom code, like for Sha256, but it works out of the box :D
|
||||
|
Reference in New Issue
Block a user