db_dump/
keywords.rs

1//! <b style="font-variant:small-caps">keywords.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 **keywords.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 KeywordId(pub u32);
14
15/// One row of **keywords.csv**.
16#[derive(Deserialize, Clone, Debug)]
17#[serde(deny_unknown_fields)]
18#[non_exhaustive]
19pub struct Row {
20    /// PRIMARY KEY
21    pub id: KeywordId,
22    /// UNIQUE
23    pub keyword: String,
24    pub crates_cnt: u32,
25    #[serde(deserialize_with = "crate::datetime::de")]
26    pub created_at: DateTime<Utc>,
27}
28
29impl Ord for Row {
30    fn cmp(&self, other: &Self) -> Ordering {
31        KeywordId::cmp(&self.id, &other.id)
32    }
33}
34
35impl PartialOrd for Row {
36    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
37        Some(self.cmp(other))
38    }
39}
40
41impl Eq for Row {}
42
43impl PartialEq for Row {
44    fn eq(&self, other: &Self) -> bool {
45        KeywordId::eq(&self.id, &other.id)
46    }
47}
48
49impl Hash for Row {
50    fn hash<H: Hasher>(&self, state: &mut H) {
51        KeywordId::hash(&self.id, state);
52    }
53}
54
55impl Borrow<KeywordId> for Row {
56    fn borrow(&self) -> &KeywordId {
57        &self.id
58    }
59}