Skip to content

Commit

Permalink
style: fix deprecation warning in rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerschtli committed Dec 30, 2024
1 parent 8a47b12 commit d8933c9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 33 deletions.
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ normalize_doc_attributes = true
reorder_impl_items = true
use_field_init_shorthand = true
use_try_shorthand = true
version = "Two"
style_edition = "2021"
wrap_comments = true
2 changes: 1 addition & 1 deletion src/features/network/data.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::feature::Renderable;

use super::RenderConfig;
use super::PLACEHOLDER_ESSID;
use super::PLACEHOLDER_IPV4;
use super::PLACEHOLDER_IPV6;
use super::PLACEHOLDER_LOCAL_IPV4;
use super::PLACEHOLDER_LOCAL_IPV6;
use super::RenderConfig;

#[derive(Debug)]
pub(super) struct Data {
Expand Down
64 changes: 39 additions & 25 deletions src/features/network/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::feature;
use crate::wrapper::process;

use super::Data;
use super::FEATURE_NAME;
use super::UpdateConfig;
use super::FEATURE_NAME;

enum IpAddress {
V4,
Expand All @@ -27,10 +27,14 @@ struct Route {

impl fmt::Display for IpAddress {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "IPv{}", match self {
IpAddress::V4 => 4,
IpAddress::V6 => 6,
})
write!(
f,
"IPv{}",
match self {
IpAddress::V4 => 4,
IpAddress::V6 => 6,
}
)
}
}

Expand All @@ -49,7 +53,11 @@ impl Updater {
enabled: bool,
builder: F,
) -> Option<String> {
if enabled { builder() } else { None }
if enabled {
builder()
} else {
None
}
}
}

Expand Down Expand Up @@ -85,16 +93,19 @@ fn essid() -> Option<String> {
}

fn local_address(address_type: &IpAddress) -> Option<String> {
let command = process::Command::new("ip", &[
match address_type {
IpAddress::V4 => "-4",
IpAddress::V6 => "-6",
},
"-j",
"route",
"show",
"default",
]);
let command = process::Command::new(
"ip",
&[
match address_type {
IpAddress::V4 => "-4",
IpAddress::V6 => "-6",
},
"-j",
"route",
"show",
"default",
],
);

let output = normalize_output(command.output().wrap_error(
FEATURE_NAME,
Expand Down Expand Up @@ -128,15 +139,18 @@ fn local_address(address_type: &IpAddress) -> Option<String> {
}

fn ip_address(address_type: &IpAddress) -> Option<String> {
let mut command = process::Command::new("dig", &[
// decrease time and tries because commands are executed synchronously
// TODO: make asychronous
"+time=3", // default: 5 seconds
"+tries=1", // default: 3
"@resolver1.opendns.com",
"myip.opendns.com",
"+short",
]);
let mut command = process::Command::new(
"dig",
&[
// decrease time and tries because commands are executed synchronously
// TODO: make asychronous
"+time=3", // default: 5 seconds
"+tries=1", // default: 3
"@resolver1.opendns.com",
"myip.opendns.com",
"+short",
],
);

command.args(match address_type {
IpAddress::V4 => ["A", "-4"],
Expand Down
2 changes: 1 addition & 1 deletion src/wrapper/dbus.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub(crate) use dbus::Path;
use dbus::ffidisp::BusType;
use dbus::ffidisp::Connection as DbusConnection;
use dbus::ffidisp::ConnectionItem;
pub(crate) use dbus::Path;

use crate::error::Result;
use crate::error::WrapErrorExt;
Expand Down
8 changes: 3 additions & 5 deletions src/wrapper/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ where
pub(crate) fn run(self) -> Result<()> {
thread::Builder::new()
.name(self.name.to_owned())
.spawn(move || {
loop {
self.runnable.run().show_error_and_ignore();
sleep_secs(2);
}
.spawn(move || loop {
self.runnable.run().show_error_and_ignore();
sleep_secs(2);
})
.wrap_error("thread start", "failed to create thread")?;

Expand Down

0 comments on commit d8933c9

Please sign in to comment.