db_dump/
categories.rs

1//! <b style="font-variant:small-caps">categories.csv</b>
2
3use chrono::{DateTime, Utc};
4use serde_derive::{Deserialize, Serialize};
5use std::borrow::Borrow;
6use std::cmp::Ordering;
7use std::hash::{Hash, Hasher};
8
9/// Primary key of **categories.csv**.
10#[derive(Serialize, Deserialize, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
11#[serde(transparent)]
12#[cfg_attr(not(doc), repr(transparent))]
13pub struct CategoryId(pub u32);
14
15/// One row of **categories.csv**.
16#[derive(Deserialize, Clone, Debug)]
17#[serde(deny_unknown_fields)]
18#[non_exhaustive]
19pub struct Row {
20    /// PRIMARY KEY
21    pub id: CategoryId,
22    /// UNIQUE
23    pub category: String,
24    /// UNIQUE
25    pub slug: String,
26    pub description: String,
27    pub crates_cnt: u32,
28    #[serde(deserialize_with = "crate::datetime::de")]
29    pub created_at: DateTime<Utc>,
30    pub path: String,
31}
32
33impl Ord for Row {
34    fn cmp(&self, other: &Self) -> Ordering {
35        CategoryId::cmp(&self.id, &other.id)
36    }
37}
38
39impl PartialOrd for Row {
40    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
41        Some(self.cmp(other))
42    }
43}
44
45impl Eq for Row {}
46
47impl PartialEq for Row {
48    fn eq(&self, other: &Self) -> bool {
49        CategoryId::eq(&self.id, &other.id)
50    }
51}
52
53impl Hash for Row {
54    fn hash<H: Hasher>(&self, state: &mut H) {
55        CategoryId::hash(&self.id, state);
56    }
57}
58
59impl Borrow<CategoryId> for Row {
60    fn borrow(&self) -> &CategoryId {
61        &self.id
62    }
63}