summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-09-16 21:13:35 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-09-17 21:28:52 +0800
commita3b597ba7efbf7e0ddbe9d72e7202ea7a6b286a9 (patch)
treeef2ab58378c6f5009f9aa4d8560dd34bb6861f9b
parent368aee800658e9c1a9a30871c45fc6034cceda48 (diff)
perf: use explicit 'a lifetime instead of 'static
-rw-r--r--src/client/client.rs10
-rw-r--r--src/client/connector.rs2
-rw-r--r--src/client/connector/httpconnector.rs2
-rw-r--r--src/client/executor.rs8
-rw-r--r--src/tasks.rs12
5 files changed, 17 insertions, 17 deletions
diff --git a/src/client/client.rs b/src/client/client.rs
index 36afcf0..73a2c30 100644
--- a/src/client/client.rs
+++ b/src/client/client.rs
@@ -4,14 +4,14 @@ use whoami::{DesktopEnv, Language};
use crate::connector::Connection;
-pub struct Client<C: Connection> {
+pub struct Client<'a, C: Connection> {
pub connector: C,
ip: Option<IpAddr>,
hostname: String,
device_name: String,
- os: &'static str,
- cpu_arch: &'static str,
+ os: &'a str,
+ cpu_arch: &'a str,
distro: String,
desktop_env: DesktopEnv,
username: String,
@@ -20,7 +20,7 @@ pub struct Client<C: Connection> {
env: Vec<(String, String)>,
}
-impl<C: Connection> std::fmt::Display for Client<C> {
+impl<'a, C: Connection> std::fmt::Display for Client<'a, C> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
@@ -40,7 +40,7 @@ impl<C: Connection> std::fmt::Display for Client<C> {
}
}
-impl<C: Connection> Client<C> {
+impl<'a, C: Connection> Client<'a, C> {
pub fn new(connector: C) -> Result<Self, C::Err> {
let c = Self {
ip: connector.get_ip(),
diff --git a/src/client/connector.rs b/src/client/connector.rs
index 6c002c9..942c8f9 100644
--- a/src/client/connector.rs
+++ b/src/client/connector.rs
@@ -26,7 +26,7 @@ pub trait Connection {
_ = Executor::new(&NETWORK_T, ["on".to_string()]);
}
- fn init(&self, c: &Client<Self>) -> std::result::Result<(), Self::Err>
+ fn init<'a>(&self, c: &crate::client::Client<'a, Self>) -> std::result::Result<(), Self::Err>
where
Self: std::marker::Sized,
{
diff --git a/src/client/connector/httpconnector.rs b/src/client/connector/httpconnector.rs
index a418b97..c6be503 100644
--- a/src/client/connector/httpconnector.rs
+++ b/src/client/connector/httpconnector.rs
@@ -7,7 +7,7 @@ use reqwest::{
use std::{net::IpAddr, thread::sleep, time::Duration};
pub struct HTTPConnector {
- network_enforcer: Executor,
+ network_enforcer: Executor<'static>,
pull_url: Url,
ntfy_url: Url,
ip_getter_url: Url,
diff --git a/src/client/executor.rs b/src/client/executor.rs
index 379c832..35e3f75 100644
--- a/src/client/executor.rs
+++ b/src/client/executor.rs
@@ -1,13 +1,13 @@
use remote_control_rs::tasks::{IntoTaskErr, Task};
-pub struct Executor {
- task: &'static Task,
+pub struct Executor<'a> {
+ task: &'a Task<'a>,
args: Box<[String]>,
output: Option<Result<String, String>>,
}
-impl Executor {
- pub fn new(task: &'static Task, args: impl IntoIterator<Item = String>) -> Result<Self, IntoTaskErr> {
+impl<'a> Executor<'a> {
+ pub fn new(task: &'a Task<'a>, args: impl IntoIterator<Item = String>) -> Result<Self, IntoTaskErr> {
Ok(Self { task: task, args: args.into_iter().collect(), output: None })
}
diff --git a/src/tasks.rs b/src/tasks.rs
index ad41a35..1793091 100644
--- a/src/tasks.rs
+++ b/src/tasks.rs
@@ -1,17 +1,17 @@
-pub struct Task {
- pub name: &'static str,
+pub struct Task<'a> {
+ pub name: &'a str,
pub exec: fn(&[String]) -> Result<String, String>,
}
-impl PartialEq for &Task {
+impl<'a> PartialEq for &'a Task<'a> {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
}
}
-pub const TASKS: &[Task] = &[Task { name: "nop", exec: no_op }, Task { name: "exec", exec: exec }, NETWORK_T];
+pub const TASKS: &[Task<'static>] = &[Task { name: "nop", exec: no_op }, Task { name: "exec", exec: exec }, NETWORK_T];
-pub const NETWORK_T: Task = Task { name: "network", exec: network };
+pub const NETWORK_T: Task<'static> = Task { name: "network", exec: network };
fn no_op(_: &[String]) -> Result<String, String> {
Ok("".to_string())
@@ -115,7 +115,7 @@ pub enum IntoTaskErr {
NotFound(String),
}
-impl TryFrom<&str> for &Task {
+impl<'a> TryFrom<&str> for &'a Task<'a> {
type Error = IntoTaskErr;
fn try_from(value: &str) -> Result<Self, Self::Error> {