Skip to content

Commit

Permalink
Clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jkilpatr committed Jan 12, 2024
1 parent 73e61d9 commit be2071c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions althea_kernel_interface/src/hardware_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn get_kernel_version() -> Result<String, Error> {
let sys_kernel_ver_error = Err(Error::FailedToGetSystemKernelVersion);

let lines = get_lines("/proc/version")?;
let line = match lines.get(0) {
let line = match lines.first() {
Some(line) => line,
None => return sys_kernel_ver_error,
};
Expand Down Expand Up @@ -154,7 +154,7 @@ fn get_sys_uptime() -> Result<Duration, Error> {
let sys_time_error = Err(Error::FailedToGetSystemTime);

let lines = get_lines("/proc/uptime")?;
let line = match lines.get(0) {
let line = match lines.first() {
Some(line) => line,
None => return sys_time_error,
};
Expand All @@ -179,7 +179,7 @@ fn get_load_avg() -> Result<(f32, f32, f32), Error> {
// cpu load average
let load_average_error = Err(Error::FailedToGetLoadAverage);
let lines = get_lines("/proc/loadavg")?;
let load_avg = match lines.get(0) {
let load_avg = match lines.first() {
Some(line) => line,
None => return load_average_error,
};
Expand Down Expand Up @@ -243,7 +243,7 @@ fn get_numcpus() -> Result<u32, Error> {
fn maybe_get_single_line_u64(path: &str) -> Option<u64> {
match get_lines(path) {
Ok(line) => {
let var_name = line.get(0);
let var_name = line.first();
match var_name {
Some(val) => match val.parse() {
Ok(res) => Some(res),
Expand All @@ -258,7 +258,7 @@ fn maybe_get_single_line_u64(path: &str) -> Option<u64> {

pub fn maybe_get_single_line_string(path: &str) -> Option<String> {
match get_lines(path) {
Ok(line) => line.get(0).map(|val| val.to_string()),
Ok(line) => line.first().map(|val| val.to_string()),
Err(_e) => None,
}
}
Expand Down
6 changes: 3 additions & 3 deletions althea_kernel_interface/src/interface_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl dyn KernelInterface {
/// Gets the mtu from an interface
pub fn get_mtu(&self, if_name: &str) -> Result<usize, Error> {
let lines = get_lines(&format!("/sys/class/net/{if_name}/mtu"))?;
if let Some(mtu) = lines.get(0) {
if let Some(mtu) = lines.first() {
Ok(mtu.parse()?)
} else {
Err(Error::NoInterfaceError(if_name.to_string()))
Expand Down Expand Up @@ -251,7 +251,7 @@ impl dyn KernelInterface {
Ok(index.parse().unwrap())
} else {
let lines = get_lines(&format!("/sys/class/net/{if_name}/ifindex"))?;
if let Some(ifindex) = lines.get(0) {
if let Some(ifindex) = lines.first() {
Ok(ifindex.parse()?)
} else {
Err(Error::NoInterfaceError(if_name.to_string()))
Expand All @@ -263,7 +263,7 @@ impl dyn KernelInterface {
/// identical but if you have a virtual (say DSA) interface then this will be the physical interface name
pub fn get_iflink(&self, if_name: &str) -> Result<usize, Error> {
let lines = get_lines(&format!("/sys/class/net/{if_name}/iflink"))?;
if let Some(iflink) = lines.get(0) {
if let Some(iflink) = lines.first() {
Ok(iflink.parse()?)
} else {
Err(Error::NoInterfaceError(if_name.to_string()))
Expand Down
2 changes: 1 addition & 1 deletion antenna_forwarding_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn start_antenna_forwarding_proxy<S: 'static + std::marker::Send + ::std::ha
) {
Ok(messages) => {
// read messages will return a vec of at least one,
match messages.get(0) {
match messages.first() {
Some(ForwardingProtocolMessage::ForwardMessage {
ip,
server_port: _server_port,
Expand Down
8 changes: 4 additions & 4 deletions babel_monitor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ ok\n";
#[test]
fn neigh_parse() {
let neighs = parse_neighs_sync(TABLE.to_string()).unwrap();
let neigh = neighs.get(0);
let neigh = neighs.first();
assert!(neigh.is_some());
let neigh = neigh.unwrap();
assert_eq!(neighs.len(), 4);
Expand All @@ -445,7 +445,7 @@ ok\n";
let routes = parse_routes_sync(TABLE.to_string()).unwrap();
assert_eq!(routes.len(), 5);

let route = routes.get(0).unwrap();
let route = routes.first().unwrap();
assert_eq!(route.price, 3072);
}

Expand All @@ -454,7 +454,7 @@ ok\n";
let interfaces = parse_interfaces_sync(TABLE.to_string()).unwrap();
assert_eq!(interfaces.len(), 5);

let iface = interfaces.get(0).unwrap();
let iface = interfaces.first().unwrap();
assert!(!iface.up);
let iface = interfaces.get(2).unwrap();
assert_eq!(iface.ipv4, Some("10.0.236.201".parse().unwrap()));
Expand All @@ -478,7 +478,7 @@ ok\n";
let routes = parse_routes_sync(input).unwrap();
assert_eq!(routes.len(), 5);

let route = routes.get(0).unwrap();
let route = routes.first().unwrap();
assert_eq!(route.price, 3072);
// assert that these are equal within the minimum comparison difference
// of float values
Expand Down
2 changes: 1 addition & 1 deletion rita_client/src/rita_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ pub fn update_dns_conf() {
(Ok(dns_server_list), Ok(router_internal_ip)) => {
// an empty list uses the system resolver, this is acceptable since we just set the system resolver to
// point at the exit internal ip above
if let Some(first_server_list_entry) = dns_server_list.get(0) {
if let Some(first_server_list_entry) = dns_server_list.first() {
if *first_server_list_entry != router_internal_ip {
let mut dns_server_list = dns_server_list;
dns_server_list.insert(0, router_internal_ip);
Expand Down

0 comments on commit be2071c

Please sign in to comment.