1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use std::collections::HashMap;
use url::Url;

/// A List of [`Definition`].
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct DefinitionList {
    /// The inner list
    pub list: Vec<Definition>,

    /// Unknown k/vs
    #[serde(flatten)]
    pub unknown: HashMap<String, serde_json::Value>,
}

/// A [`Definition`] for a term.
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Definition {
    /// The author
    pub author: String,

    /// The current votes for this
    pub current_vote: String,

    /// The definition id
    pub defid: u64,

    /// The actual definition
    pub definition: String,

    /// An example usage
    pub example: String,

    /// The definition permalink
    pub permalink: Url,

    /// # of thumbs down
    pub thumbs_down: u64,

    /// # of thumbs up
    pub thumbs_up: u64,

    /// The term
    pub word: String,

    /// Date written
    pub written_on: String,

    /// Unknown K/Vs
    #[serde(flatten)]
    pub unknown: HashMap<String, serde_json::Value>,
}

impl Definition {
    /// Get the raw definition.
    pub fn get_raw_definition(&self) -> String {
        self.definition
            .chars()
            .filter(|&c| c != '[' && c != ']')
            .collect()
    }

    /// Get the raw example.
    pub fn get_raw_example(&self) -> String {
        self.example
            .chars()
            .filter(|&c| c != '[' && c != ']')
            .collect()
    }
}