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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
pub mod connection;
pub mod reply;
pub mod status;
pub mod url;

use std::convert::From;
use std::default::Default;

#[derive(Debug)]
pub struct Database {
    pub name: String,
    pub desc: String,
}

impl From<String> for Database {
    fn from(src: String) -> Self {
        Self {
            name: src,
            desc: String::new(),
        }
    }
}

impl Database {
    pub fn all() -> Self {
        Database {
            name: String::from("*"),
            desc: String::from("All databases"),
        }
    }

    pub fn first() -> Self {
        Database {
            name: String::from("!"),
            desc: String::from("All databases (first match)"),
        }
    }
}

impl Default for Database {
    fn default() -> Self {
        Self::first()
    }
}

#[derive(Debug)]
pub struct Definition {
    pub source: Database,
    pub text: Vec<String>,
}

impl Definition {
    pub fn empty() -> Self {
        Definition {
            source: Database::all(),
            text: vec![String::from("No definition")],
        }
    }
}

#[derive(Debug)]
pub struct Strategy {
    pub name: String,
    pub desc: String,
}

impl From<String> for Strategy {
    fn from(src: String) -> Self {
        Strategy {
            name: src,
            desc: String::new(),
        }
    }
}

impl Strategy {
    pub fn exact() -> Self {
        Self::from(String::from("exact"))
    }

    pub fn prefix() -> Self {
        Self::from(String::from("prefix"))
    }
}

impl Default for Strategy {
    fn default() -> Self {
        Self {
            name: String::from("."),
            desc: String::from("Server default"),
        }
    }
}

#[derive(Debug)]
pub struct Match {
    pub source: Database,
    pub word: String,
}