summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-01-02 16:10:12 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-01-02 16:10:25 +0100
commitf53951a43c887963605b52b30237b8aa61aa7c09 (patch)
treebe0fa55133b015c5daf7e2d1b2ea9d50fbeef44e
parentd7df41df65d3928391ecb658da9d0c63a0966250 (diff)
Replace implementation of getters with getset::Gettersmy-master
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--Cargo.lock37
-rw-r--r--Cargo.toml1
-rw-r--r--src/config.rs43
-rw-r--r--src/main.rs1
4 files changed, 54 insertions, 28 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ab238b5..727385c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -87,6 +87,7 @@ dependencies = [
"clap",
"dimensioned",
"error-chain",
+ "getset",
"log 0.4.11",
"regex",
"rocket",
@@ -413,6 +414,18 @@ dependencies = [
]
[[package]]
+name = "getset"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "24b328c01a4d71d2d8173daa93562a73ab0fe85616876f02500f53d82948c504"
+dependencies = [
+ "proc-macro-error",
+ "proc-macro2 1.0.24",
+ "quote 1.0.8",
+ "syn 1.0.57",
+]
+
+[[package]]
name = "ghash"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -802,6 +815,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
+name = "proc-macro-error"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
+dependencies = [
+ "proc-macro-error-attr",
+ "proc-macro2 1.0.24",
+ "quote 1.0.8",
+ "syn 1.0.57",
+ "version_check 0.9.2",
+]
+
+[[package]]
+name = "proc-macro-error-attr"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
+dependencies = [
+ "proc-macro2 1.0.24",
+ "quote 1.0.8",
+ "version_check 0.9.2",
+]
+
+[[package]]
name = "proc-macro2"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 6554e12..8e1693b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,6 +16,7 @@ serde_derive = "1"
serde_json = "1"
simplelog = "^0.4.3"
toml = "^0.5"
+getset = "0.1"
[dependencies.chrono]
features = [ "serde" ]
diff --git a/src/config.rs b/src/config.rs
index 9441973..c2aa960 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -6,6 +6,7 @@ extern crate toml;
use std::path::PathBuf;
use regex::Regex;
use error::*;
+use getset::Getters;
//------------------------------------//
// structs for deserialization //
@@ -56,11 +57,21 @@ impl ConfigDeser {
/// The deserialized Item would nearly always require some operation on its
/// contents to use it, so we do those operations beforehand and only access
/// the useful data from main().
+#[derive(Getters)]
pub struct LogItem {
+ #[getset(get = "pub")]
file : String,
+
+ #[getset(get = "pub")]
regex : Regex,
+
+ #[getset(get = "pub")]
alias : String,
+
+ #[getset(get = "pub")]
capture_names : Vec<String>,
+
+ #[getset(get = "pub")]
aliases : Vec<String>,
}
@@ -105,31 +116,15 @@ impl LogItem {
}
)
}
-
- pub fn file(&self) -> &String {
- &self.file
- }
-
- pub fn regex(&self) -> &Regex {
- &self.regex
- }
-
- pub fn alias(&self) -> &String {
- &self.alias
- }
-
- pub fn capture_names(&self) -> &Vec<String> {
- &self.capture_names
- }
-
- pub fn aliases(&self) -> &Vec<String> {
- &self.aliases
- }
}
/// Contains more immediately usable data
+#[derive(Getters)]
pub struct Config {
+ #[getset(get = "pub")]
items : Vec<LogItem>,
+
+ #[getset(get = "pub")]
all_aliases : Vec<String>,
}
@@ -155,13 +150,5 @@ impl Config {
Ok(Config { items: l_items, all_aliases : all_als })
}
-
- pub fn items(&self) -> &Vec<LogItem> {
- &self.items
- }
-
- pub fn all_aliases(&self) -> &Vec<String> {
- &self.all_aliases
- }
}
diff --git a/src/main.rs b/src/main.rs
index 6b3c2d6..3eb81f9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -18,6 +18,7 @@ extern crate serde;
extern crate serde_derive;
extern crate serde_json;
extern crate simplelog;
+extern crate getset;
use std::collections::HashMap;
use std::fs::File;