summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2022-06-19 18:22:20 +0200
committerMatthias Beyer <mail@beyermatthias.de>2022-11-28 17:29:12 +0100
commit1c208199ba9f9608d56a9882957a767d9ca4fa05 (patch)
treef3a51d22b2cde309c5b944cf7f8c8c6dc7832917
parenta16e50540957d2ab3cd98794486ed6834c2a953a (diff)
Remove "watch" example
This patch removes the "watch" example. The idea should be straight forward to a decently experienced rust dev, and (to be honest) I am too lazy right now to update the example for the removed (because deprecated) interfaces. Shame on me. If someone wants to provide this example again, I'm happy to see this patch reverted and the example adapted. ;-) Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--examples/watch/Settings.toml3
-rw-r--r--examples/watch/main.rs81
2 files changed, 0 insertions, 84 deletions
diff --git a/examples/watch/Settings.toml b/examples/watch/Settings.toml
deleted file mode 100644
index 1518068..0000000
--- a/examples/watch/Settings.toml
+++ /dev/null
@@ -1,3 +0,0 @@
-debug = false
-port = 3223
-host = "0.0.0.0"
diff --git a/examples/watch/main.rs b/examples/watch/main.rs
deleted file mode 100644
index ca83572..0000000
--- a/examples/watch/main.rs
+++ /dev/null
@@ -1,81 +0,0 @@
-#![allow(deprecated)]
-use config::{Config, File};
-use notify::{Event, RecommendedWatcher, RecursiveMode, Watcher};
-use std::collections::HashMap;
-use std::path::Path;
-use std::sync::mpsc::channel;
-use std::sync::RwLock;
-use std::time::Duration;
-
-lazy_static::lazy_static! {
- static ref SETTINGS: RwLock<Config> = RwLock::new({
- let mut settings = Config::default();
- settings.merge(File::with_name("examples/watch/Settings.toml")).unwrap();
-
- settings
- });
-}
-
-fn show() {
- println!(
- " * Settings :: \n\x1b[31m{:?}\x1b[0m",
- SETTINGS
- .read()
- .unwrap()
- .clone()
- .try_deserialize::<HashMap<String, String>>()
- .unwrap()
- );
-}
-
-fn watch() {
- // Create a channel to receive the events.
- let (tx, rx) = channel();
-
- // Automatically select the best implementation for your platform.
- // You can also access each implementation directly e.g. INotifyWatcher.
- let mut watcher: RecommendedWatcher = Watcher::new(
- tx,
- notify::Config::default().with_poll_interval(Duration::from_secs(2)),
- )
- .unwrap();
-
- // Add a path to be watched. All files and directories at that path and
- // below will be monitored for changes.
- watcher
- .watch(
- Path::new("examples/watch/Settings.toml"),
- RecursiveMode::NonRecursive,
- )
- .unwrap();
-
- // This is a simple loop, but you may want to use more complex logic here,
- // for example to handle I/O.
- loop {
- match rx.recv() {
- Ok(Ok(Event {
- kind: notify::event::EventKind::Modify(_),
- ..
- })) => {
- println!(" * Settings.toml written; refreshing configuration ...");
- SETTINGS.write().unwrap().refresh().unwrap();
- show();
- }
-
- Err(e) => println!("watch error: {:?}", e),
-
- _ => {
- // Ignore event
- }
- }
- }
-}
-
-fn main() {
- // This is just an example of what could be done, today
- // We do want this to be built-in to config-rs at some point
- // Feel free to take a crack at a PR
-
- show();
- watch();
-}