Skip to content

Commit 9114257

Browse files
committed
refactor: 优化代码格式,清理冗余和不必要的换行
1 parent c1a85ee commit 9114257

File tree

12 files changed

+62
-41
lines changed

12 files changed

+62
-41
lines changed

fdt-edit/examples/fdt_debug_demo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! FDT 深度调试演示
2-
//!
2+
//!
33
//! 演示如何使用新的深度调试功能来遍历和打印设备树的所有节点
44
5-
use fdt_edit::Fdt;
65
use dtb_file::fdt_rpi_4b;
6+
use fdt_edit::Fdt;
77

88
fn main() -> Result<(), Box<dyn std::error::Error>> {
99
env_logger::init();

fdt-edit/src/fdt.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub use fdt_raw::MemoryReservation;
99
use fdt_raw::{FdtError, Phandle, Status};
1010

1111
use crate::{
12-
Node, NodeIter, NodeIterMut, NodeMut, NodeRef, NodeKind, ClockType,
12+
ClockType, Node, NodeIter, NodeIterMut, NodeKind, NodeMut, NodeRef,
1313
encode::{FdtData, FdtEncoder},
1414
};
1515

@@ -492,7 +492,11 @@ impl core::fmt::Display for Fdt {
492492

493493
// 输出内存保留块
494494
for reservation in &self.memory_reservations {
495-
writeln!(f, "/memreserve/ 0x{:x} 0x{:x};", reservation.address, reservation.size)?;
495+
writeln!(
496+
f,
497+
"/memreserve/ 0x{:x} 0x{:x};",
498+
reservation.address, reservation.size
499+
)?;
496500
}
497501

498502
// 输出根节点
@@ -522,7 +526,11 @@ impl Fdt {
522526
fn fmt_debug_deep(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
523527
writeln!(f, "Fdt {{")?;
524528
writeln!(f, " boot_cpuid_phys: 0x{:x},", self.boot_cpuid_phys)?;
525-
writeln!(f, " memory_reservations_count: {},", self.memory_reservations.len())?;
529+
writeln!(
530+
f,
531+
" memory_reservations_count: {},",
532+
self.memory_reservations.len()
533+
)?;
526534
writeln!(f, " phandle_cache_size: {},", self.phandle_cache.len())?;
527535
writeln!(f, " nodes:")?;
528536

@@ -534,7 +542,13 @@ impl Fdt {
534542
writeln!(f, "}}")
535543
}
536544

537-
fn fmt_node_debug(&self, f: &mut core::fmt::Formatter<'_>, node: &NodeRef, indent: usize, index: usize) -> core::fmt::Result {
545+
fn fmt_node_debug(
546+
&self,
547+
f: &mut core::fmt::Formatter<'_>,
548+
node: &NodeRef,
549+
indent: usize,
550+
index: usize,
551+
) -> core::fmt::Result {
538552
// 打印缩进
539553
for _ in 0..indent {
540554
write!(f, " ")?;
@@ -580,8 +594,7 @@ impl Fdt {
580594
if !regions.is_empty() {
581595
write!(f, " ({} regions", regions.len())?;
582596
for (i, region) in regions.iter().take(2).enumerate() {
583-
write!(f, ", [{}]: 0x{:x}+0x{:x}",
584-
i, region.address, region.size)?;
597+
write!(f, ", [{}]: 0x{:x}+0x{:x}", i, region.address, region.size)?;
585598
}
586599
if regions.len() > 2 {
587600
write!(f, ", ...")?;

fdt-edit/src/node/clock.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use core::ops::Deref;
22

3-
use alloc::{string::{String, ToString}, vec::Vec};
3+
use alloc::{
4+
string::{String, ToString},
5+
vec::Vec,
6+
};
47
use fdt_raw::Phandle;
58

69
use crate::node::gerneric::NodeRefGen;
@@ -201,12 +204,7 @@ impl<'a> NodeRefClock<'a> {
201204
// 从 clock-names 获取对应的名称
202205
let name = clock_names.get(index).cloned();
203206

204-
clocks.push(ClockRef::with_name(
205-
name,
206-
phandle,
207-
clock_cells,
208-
specifier,
209-
));
207+
clocks.push(ClockRef::with_name(name, phandle, clock_cells, specifier));
210208
index += 1;
211209
}
212210

@@ -220,4 +218,4 @@ impl<'a> Deref for NodeRefClock<'a> {
220218
fn deref(&self) -> &Self::Target {
221219
&self.node
222220
}
223-
}
221+
}

fdt-edit/src/node/interrupt_controller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ fn is_interrupt_controller_node(node: &NodeRefGen) -> bool {
6161

6262
// 或者有 interrupt-controller 属性
6363
node.find_property("interrupt-controller").is_some()
64-
}
64+
}

fdt-edit/src/node/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use core::{
77
use alloc::vec::Vec;
88

99
use crate::{
10-
Context, Node, NodeRefPci, NodeRefClock, NodeRefInterruptController, NodeRefMemory, NodeKind,
10+
Context, Node, NodeKind, NodeRefClock, NodeRefInterruptController, NodeRefMemory, NodeRefPci,
1111
node::gerneric::{NodeMutGen, NodeRefGen},
1212
};
1313

fdt-edit/src/node/memory.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use core::ops::Deref;
22

3-
use alloc::{string::{String, ToString}, vec::Vec};
3+
use alloc::{
4+
string::{String, ToString},
5+
vec::Vec,
6+
};
47
use fdt_raw::MemoryRegion;
58

69
use crate::node::gerneric::NodeRefGen;
@@ -65,10 +68,7 @@ impl<'a> NodeRefMemory<'a> {
6568
reader.read_cells(address_cells),
6669
reader.read_cells(size_cells),
6770
) {
68-
regions.push(MemoryRegion {
69-
address,
70-
size,
71-
});
71+
regions.push(MemoryRegion { address, size });
7272
}
7373
}
7474
regions
@@ -92,12 +92,12 @@ impl<'a> Deref for NodeRefMemory<'a> {
9292
/// 检查节点是否是 memory 节点
9393
fn is_memory_node(node: &NodeRefGen) -> bool {
9494
// 检查 device_type 属性是否为 "memory"
95-
if let Some(device_type) = node.device_type() {
96-
if device_type == "memory" {
97-
return true;
98-
}
95+
if let Some(device_type) = node.device_type()
96+
&& device_type == "memory"
97+
{
98+
return true;
9999
}
100100

101101
// 或者节点名以 "memory" 开头
102102
node.name().starts_with("memory")
103-
}
103+
}

fdt-edit/src/node/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,3 @@ impl From<&fdt_raw::Node<'_>> for Node {
311311
new_node
312312
}
313313
}
314-

fdt-edit/tests/clock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![cfg(unix)]
22

33
use dtb_file::*;
4-
use fdt_edit::*;
54
use fdt_edit::NodeKind;
5+
use fdt_edit::*;
66

77
#[cfg(test)]
88
mod tests {

fdt-edit/tests/display_debug.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,12 @@ mod tests {
227227
assert!(deep_debug.contains("[000]"));
228228

229229
// 验证包含特定节点类型
230-
assert!(deep_debug.contains("Clock") || deep_debug.contains("InterruptController") ||
231-
deep_debug.contains("Memory") || deep_debug.contains("Generic"));
230+
assert!(
231+
deep_debug.contains("Clock")
232+
|| deep_debug.contains("InterruptController")
233+
|| deep_debug.contains("Memory")
234+
|| deep_debug.contains("Generic")
235+
);
232236
}
233237

234238
#[test]
@@ -242,7 +246,12 @@ mod tests {
242246

243247
let mut uart = Node::new("uart@9000000");
244248
uart.set_property(Property::new("compatible", b"arm,pl011\0".to_vec()));
245-
uart.set_property(Property::new("reg", vec![0x00, 0x90, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00]));
249+
uart.set_property(Property::new(
250+
"reg",
251+
vec![
252+
0x00, 0x90, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
253+
],
254+
));
246255
uart.set_property(Property::new("status", b"okay\0".to_vec()));
247256

248257
soc.add_child(uart);
@@ -259,4 +268,4 @@ mod tests {
259268
assert!(deep_debug.contains("#address-cells=1"));
260269
assert!(deep_debug.contains("#size-cells=1"));
261270
}
262-
}
271+
}

fdt-edit/tests/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![cfg(unix)]
22

33
use dtb_file::*;
4-
use fdt_edit::*;
54
use fdt_edit::NodeKind;
5+
use fdt_edit::*;
66

77
#[cfg(test)]
88
mod tests {

0 commit comments

Comments
 (0)