pub struct Periodic<T, P: Time = Minutes<1>> { /* private fields */ }Expand description
Given a Path from the user, provides a utility that reloads the file
at the path at a fixed interval
- Use
Periodic::getto get the file contents at a given moment - Use
Periodic::receiverto get a tokiowatch::Receiver
§Example
use clap::Parser;
use clap_adapters::prelude::*;
#[derive(Debug, Parser)]
struct Cli {
/// Path to a Json config to be reloaded every 24 hours
#[clap(long)]
daily_config: Periodic<PathTo<JsonOf<serde_json::Value>>, Hours<24>>,
/// Path to a Json config to be reloaded every minute
#[clap(long)]
minutely_config: Periodic<PathTo<YamlOf<serde_json::Value>>>, // Minutes<1> is the default period
/// Path to a Json config to be reloaded every second
#[clap(long)]
secondly_config: Periodic<PathTo<TomlOf<serde_json::Value>>, Seconds<1>>,
}
#[tokio::main]
async fn main() {
let cli = Cli::parse_from([
"app",
"--daily_config=./daily_config.json",
"--minutely-config=./minutely_config.yaml",
"--secondly-config=./secondly_config.toml",
]);
let current_config = cli.daily_config.get();
let current_config = cli.minutely_config.get();
let current_config = cli.secondly_config.get();
let daily_config_rx = cli.daily_config.receiver();
let minutely_config_rx = cli.minutely_config.receiver();
let secondly_config_rx = cli.secondly_config.receiver();
}Note:
Periodicrequires a tokio runtime to be active before calling any of theclap::Parserfunctions
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<T, P> Freeze for Periodic<T, P>
impl<T, P> RefUnwindSafe for Periodic<T, P>where
P: RefUnwindSafe,
impl<T, P> Send for Periodic<T, P>
impl<T, P> Sync for Periodic<T, P>
impl<T, P> Unpin for Periodic<T, P>where
P: Unpin,
impl<T, P> UnwindSafe for Periodic<T, P>where
P: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more