From 016c783cc91b4ef544cf75d04118f9c5e2dea7e2 Mon Sep 17 00:00:00 2001 From: DeathWish5 Date: Wed, 11 Aug 2021 22:43:32 +0800 Subject: [PATCH] cargo fmt and cargo clippy --- code/ch02-03/object/src/ipc/channel.rs | 2 +- code/ch03-02/object/src/ipc/channel.rs | 2 +- code/ch03-04/object/src/ipc/channel.rs | 2 +- code/ch03-04/object/src/vm/vmar.rs | 3 +-- code/ch04-01/zircon-loader/src/lib.rs | 11 ++--------- code/ch04-01/zircon-object/src/ipc/channel.rs | 2 +- code/ch04-01/zircon-object/src/lib.rs | 2 +- code/ch04-01/zircon-object/src/vm/vmar.rs | 3 +-- 8 files changed, 9 insertions(+), 18 deletions(-) diff --git a/code/ch02-03/object/src/ipc/channel.rs b/code/ch02-03/object/src/ipc/channel.rs index f8f7d59..5639a8d 100644 --- a/code/ch02-03/object/src/ipc/channel.rs +++ b/code/ch02-03/object/src/ipc/channel.rs @@ -55,7 +55,7 @@ impl Channel { /// Read a packet from the channel if check is ok, otherwise the msg will keep. pub fn read(&self) -> ZxResult { let mut recv_queue = self.recv_queue.lock(); - if let Some(_) = recv_queue.front() { + if recv_queue.front().is_some() { let msg = recv_queue.pop_front().unwrap(); return Ok(msg); } diff --git a/code/ch03-02/object/src/ipc/channel.rs b/code/ch03-02/object/src/ipc/channel.rs index f8f7d59..5639a8d 100644 --- a/code/ch03-02/object/src/ipc/channel.rs +++ b/code/ch03-02/object/src/ipc/channel.rs @@ -55,7 +55,7 @@ impl Channel { /// Read a packet from the channel if check is ok, otherwise the msg will keep. pub fn read(&self) -> ZxResult { let mut recv_queue = self.recv_queue.lock(); - if let Some(_) = recv_queue.front() { + if recv_queue.front().is_some() { let msg = recv_queue.pop_front().unwrap(); return Ok(msg); } diff --git a/code/ch03-04/object/src/ipc/channel.rs b/code/ch03-04/object/src/ipc/channel.rs index f8f7d59..5639a8d 100644 --- a/code/ch03-04/object/src/ipc/channel.rs +++ b/code/ch03-04/object/src/ipc/channel.rs @@ -55,7 +55,7 @@ impl Channel { /// Read a packet from the channel if check is ok, otherwise the msg will keep. pub fn read(&self) -> ZxResult { let mut recv_queue = self.recv_queue.lock(); - if let Some(_) = recv_queue.front() { + if recv_queue.front().is_some() { let msg = recv_queue.pop_front().unwrap(); return Ok(msg); } diff --git a/code/ch03-04/object/src/vm/vmar.rs b/code/ch03-04/object/src/vm/vmar.rs index c4f2b39..961eb59 100644 --- a/code/ch03-04/object/src/vm/vmar.rs +++ b/code/ch03-04/object/src/vm/vmar.rs @@ -277,8 +277,7 @@ impl VmAddressRegion { let length = inner.mappings.iter().fold(0, |acc, map| { acc + end_addr .min(map.end_addr()) - .checked_sub(addr.max(map.addr())) - .unwrap_or(0) + .saturating_sub(addr.max(map.addr())) }); if length != len { return Err(ZxError::NOT_FOUND); diff --git a/code/ch04-01/zircon-loader/src/lib.rs b/code/ch04-01/zircon-loader/src/lib.rs index 245c6d0..947c46f 100644 --- a/code/ch04-01/zircon-loader/src/lib.rs +++ b/code/ch04-01/zircon-loader/src/lib.rs @@ -10,16 +10,9 @@ extern crate log; use { alloc::{boxed::Box, sync::Arc, vec::Vec}, core::{future::Future, pin::Pin}, - xmas_elf::ElfFile, - zircon_object::{ - dev::*, - ipc::*, - object::*, - task::*, - util::elf_loader::*, - vm::*, - }, kernel_hal::MMUFlags, + xmas_elf::ElfFile, + zircon_object::{dev::*, ipc::*, object::*, task::*, util::elf_loader::*, vm::*}, }; mod kcounter; diff --git a/code/ch04-01/zircon-object/src/ipc/channel.rs b/code/ch04-01/zircon-object/src/ipc/channel.rs index 1b8c2d8..59c6940 100644 --- a/code/ch04-01/zircon-object/src/ipc/channel.rs +++ b/code/ch04-01/zircon-object/src/ipc/channel.rs @@ -56,7 +56,7 @@ impl Channel { /// Read a packet from the channel if check is ok, otherwise the msg will keep. pub fn read(&self) -> ZxResult { let mut recv_queue = self.recv_queue.lock(); - if let Some(_) = recv_queue.front() { + if recv_queue.front().is_some() { let msg = recv_queue.pop_front().unwrap(); return Ok(msg); } diff --git a/code/ch04-01/zircon-object/src/lib.rs b/code/ch04-01/zircon-object/src/lib.rs index 951b941..9ec9f19 100644 --- a/code/ch04-01/zircon-object/src/lib.rs +++ b/code/ch04-01/zircon-object/src/lib.rs @@ -13,12 +13,12 @@ extern crate std; #[macro_use] extern crate log; +pub mod dev; pub mod error; pub mod ipc; pub mod object; pub mod task; pub mod util; pub mod vm; -pub mod dev; pub use self::error::*; diff --git a/code/ch04-01/zircon-object/src/vm/vmar.rs b/code/ch04-01/zircon-object/src/vm/vmar.rs index c4f2b39..961eb59 100644 --- a/code/ch04-01/zircon-object/src/vm/vmar.rs +++ b/code/ch04-01/zircon-object/src/vm/vmar.rs @@ -277,8 +277,7 @@ impl VmAddressRegion { let length = inner.mappings.iter().fold(0, |acc, map| { acc + end_addr .min(map.end_addr()) - .checked_sub(addr.max(map.addr())) - .unwrap_or(0) + .saturating_sub(addr.max(map.addr())) }); if length != len { return Err(ZxError::NOT_FOUND);