mirror of
https://codeberg.org/demostf/backup.git
synced 2026-06-03 18:04:08 +02:00
remove digest type from apis
This commit is contained in:
parent
cb8fbf51f7
commit
6a1851eae7
4 changed files with 11 additions and 16 deletions
13
src/api.rs
13
src/api.rs
|
|
@ -1,6 +1,5 @@
|
|||
use crate::Error;
|
||||
use chrono::{DateTime, Utc};
|
||||
use md5::Digest;
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use smol_str::SmolStr;
|
||||
use std::fmt;
|
||||
|
|
@ -24,13 +23,13 @@ pub struct Demo {
|
|||
pub player_count: u8,
|
||||
pub uploader: u32,
|
||||
#[serde(deserialize_with = "hex_to_digest")]
|
||||
pub hash: Digest,
|
||||
pub hash: [u8; 16],
|
||||
pub backend: SmolStr,
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
/// Deserializes a lowercase hex string to a `Vec<u8>`.
|
||||
pub fn hex_to_digest<'de, D>(deserializer: D) -> Result<Digest, D::Error>
|
||||
/// Deserializes a lowercase hex string to a `[u8; 16]`.
|
||||
pub fn hex_to_digest<'de, D>(deserializer: D) -> Result<[u8; 16], D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
|
|
@ -40,12 +39,10 @@ where
|
|||
let string = <&str>::deserialize(deserializer)?;
|
||||
|
||||
if string.len() == 0 {
|
||||
return Ok(Digest([0; 16]));
|
||||
return Ok([0; 16]);
|
||||
}
|
||||
|
||||
<[u8; 16]>::from_hex(string)
|
||||
.map_err(|err| Error::custom(err.to_string()))
|
||||
.map(Digest)
|
||||
<[u8; 16]>::from_hex(string).map_err(|err| Error::custom(err.to_string()))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue