summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-09-16 20:27:22 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-09-17 21:28:52 +0800
commit73b908cb44cf52a768647c0f5cd450ab48cf831f (patch)
tree5cec5d442c065a0464626e45e7c61ac97e04d63e /src/client
parent4517907896246d815d1ab2b4c67b883cd567eae0 (diff)
chore: rustfmt config change
Diffstat (limited to 'src/client')
-rw-r--r--src/client/client.rs12
-rw-r--r--src/client/connector.rs28
-rw-r--r--src/client/connector/httpconnector.rs17
-rw-r--r--src/client/executor.rs11
4 files changed, 14 insertions, 54 deletions
diff --git a/src/client/client.rs b/src/client/client.rs
index c833550..36afcf0 100644
--- a/src/client/client.rs
+++ b/src/client/client.rs
@@ -35,17 +35,7 @@ impl<C: Connection> std::fmt::Display for Client<C> {
Real Name: {}\n\
Languages: {:?}\n\
Environment Variables: {:?}\n",
- self.ip,
- self.hostname,
- self.device_name,
- self.os,
- self.cpu_arch,
- self.distro,
- self.desktop_env,
- self.username,
- self.realname,
- self.langs,
- self.env
+ self.ip, self.hostname, self.device_name, self.os, self.cpu_arch, self.distro, self.desktop_env, self.username, self.realname, self.langs, self.env
)
}
}
diff --git a/src/client/connector.rs b/src/client/connector.rs
index 735a3d3..a595c8e 100644
--- a/src/client/connector.rs
+++ b/src/client/connector.rs
@@ -42,9 +42,12 @@ pub trait Connection {
}
fn tick(&mut self) {
- // tradeoff: if I put this at the ened of the loop, then the continue would just skip it, and continue doing update() until with no waiting, this wastes lot of cpu/IO
- // however, of course we can add a manual sleep before it continue and put this in the end, but that's code duplication
- // the cons of the current approch is that the first time we've entered, it would start sleeping
+ // tradeoff: if I put this at the ened of the loop, then the continue would just
+ // skip it, and continue doing update() until with no waiting, this wastes lot
+ // of cpu/IO however, of course we can add a manual sleep before it
+ // continue and put this in the end, but that's code duplication
+ // the cons of the current approch is that the first time we've entered, it
+ // would start sleeping
self.reinit();
match self.update() {
@@ -59,26 +62,11 @@ pub trait Connection {
None => return,
};
// FIXME: handle the errors... peak prod code
- self.ntfy(
- Executor::new(task, it.map(str::to_string))
- .unwrap()
- .run()
- .unwrap()
- .clone()
- .unwrap(),
- )
- .unwrap();
+ self.ntfy(Executor::new(task, it.map(str::to_string)).unwrap().run().unwrap().clone().unwrap()).unwrap();
}
Result::Err(e) => {
#[cfg(debug_assertions)]
- std::eprintln!(
- "[{}:{}:{}] {} = {:#?}",
- std::file!(),
- std::line!(),
- std::column!(),
- std::stringify!(e),
- &&e as &dyn std::fmt::Debug,
- );
+ std::eprintln!("[{}:{}:{}] {} = {:#?}", std::file!(), std::line!(), std::column!(), std::stringify!(e), &&e as &dyn std::fmt::Debug,);
}
}
}
diff --git a/src/client/connector/httpconnector.rs b/src/client/connector/httpconnector.rs
index d8c0027..a418b97 100644
--- a/src/client/connector/httpconnector.rs
+++ b/src/client/connector/httpconnector.rs
@@ -16,11 +16,7 @@ pub struct HTTPConnector {
}
impl HTTPConnector {
- pub fn new(
- pull_url: &str,
- ntfy_url: &str,
- ip_getter_url: &str,
- ) -> std::result::Result<Self, url::ParseError> {
+ pub fn new(pull_url: &str, ntfy_url: &str, ip_getter_url: &str) -> std::result::Result<Self, url::ParseError> {
Ok(Self {
network_enforcer: Executor::new(&NETWORK_T, ["on".to_string()]).unwrap(), // .unwrap() should never panic
prev: String::new(),
@@ -35,10 +31,7 @@ impl HTTPConnector {
}
#[allow(clippy::only_used_in_recursion)]
- fn handle_response<F: Fn() -> RequestBuilder>(
- &self,
- req: F,
- ) -> Result<<HTTPConnector as Connection>::Ok, <HTTPConnector as Connection>::Err> {
+ fn handle_response<F: Fn() -> RequestBuilder>(&self, req: F) -> Result<<HTTPConnector as Connection>::Ok, <HTTPConnector as Connection>::Err> {
match req().send() {
Ok(resp) => match resp.status() {
StatusCode::TOO_MANY_REQUESTS => {
@@ -84,11 +77,7 @@ impl Connection for HTTPConnector {
}
fn ntfy(&self, data: String) -> std::result::Result<(), Self::Err> {
- self.handle_response(|| {
- self.client
- .post(self.ntfy_url.as_str())
- .body(data.to_owned())
- })?;
+ self.handle_response(|| self.client.post(self.ntfy_url.as_str()).body(data.to_owned()))?;
Ok(())
}
diff --git a/src/client/executor.rs b/src/client/executor.rs
index ad419f0..32a0fdc 100644
--- a/src/client/executor.rs
+++ b/src/client/executor.rs
@@ -7,16 +7,9 @@ pub struct Executor {
}
impl Executor {
- pub fn new(
- task: impl IntoTask,
- args: impl IntoIterator<Item = String>,
- ) -> Result<Self, IntoTaskErr> {
+ pub fn new(task: impl IntoTask, args: impl IntoIterator<Item = String>) -> Result<Self, IntoTaskErr> {
let task = task.into_task()?;
- Ok(Self {
- task: task,
- args: args.into_iter().collect(),
- output: None,
- })
+ Ok(Self { task: task, args: args.into_iter().collect(), output: None })
}
pub fn run(&mut self) -> Option<&Result<String, String>> {