Store the date when each texture was added
This commit is contained in:
@ -3,6 +3,8 @@
|
||||
#![allow(unused_variables)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use serde::de::Error;
|
||||
use serde::{Deserialize, Deserializer, Serializer};
|
||||
use std::io;
|
||||
|
||||
mod sha256;
|
||||
@ -11,16 +13,56 @@ pub use sha256::Sha256;
|
||||
mod texture_format;
|
||||
pub use texture_format::TextureFormat;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
||||
pub struct Date {
|
||||
// Keep the order for correct comparison
|
||||
pub year: u16,
|
||||
pub month: u16,
|
||||
pub day: u16,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Serialize, Deserialize, Debug, Hash)]
|
||||
|
||||
pub struct Texture {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub tags: Vec<String>,
|
||||
pub format: TextureFormat,
|
||||
pub resolution: (usize, usize),
|
||||
#[serde(
|
||||
serialize_with = "date_serialize",
|
||||
deserialize_with = "date_deserialize"
|
||||
)]
|
||||
pub added_on: Date,
|
||||
pub texture_hash: Sha256,
|
||||
}
|
||||
|
||||
fn date_serialize<S>(date: &Date, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let vector = vec![date.year, date.month, date.day];
|
||||
serializer.serialize_some(&vector)
|
||||
}
|
||||
|
||||
fn date_deserialize<'d, D>(deserializer: D) -> Result<Date, D::Error>
|
||||
where
|
||||
D: Deserializer<'d>,
|
||||
{
|
||||
let data = Vec::<u16>::deserialize(deserializer)?;
|
||||
if data.len() != 3 {
|
||||
Err(D::Error::custom(
|
||||
"expected an array with three elements to form a date",
|
||||
))
|
||||
} else {
|
||||
Ok(Date {
|
||||
year: data[0],
|
||||
month: data[1],
|
||||
day: data[2],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ReplaceTextureStatus {
|
||||
/// Done.
|
||||
Ok,
|
||||
|
Reference in New Issue
Block a user