Skip to content

Commit 87df0d0

Browse files
committed
add Display
1 parent 6422029 commit 87df0d0

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

svd-parser/src/expand.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use anyhow::{anyhow, Result};
44
use std::collections::HashMap;
5+
use std::fmt;
56
use std::mem::take;
67
use svd_rs::{
78
array::names, cluster, field, peripheral, register, BitRange, Cluster, ClusterInfo, DeriveFrom,
@@ -50,6 +51,17 @@ impl BlockPath {
5051
}
5152
}
5253

54+
impl fmt::Display for BlockPath {
55+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56+
f.write_str(&self.peripheral)?;
57+
for p in &self.path {
58+
f.write_str(".")?;
59+
f.write_str(p)?;
60+
}
61+
Ok(())
62+
}
63+
}
64+
5365
/// Path to `register` element
5466
#[derive(Clone, Debug, PartialEq, Hash, Eq)]
5567
pub struct RegisterPath {
@@ -78,6 +90,15 @@ impl RegisterPath {
7890
}
7991
}
8092

93+
impl fmt::Display for RegisterPath {
94+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
95+
self.block.fmt(f)?;
96+
f.write_str(".")?;
97+
f.write_str(&self.name)?;
98+
Ok(())
99+
}
100+
}
101+
81102
/// Path to `field` element
82103
#[derive(Clone, Debug, PartialEq, Hash, Eq)]
83104
pub struct FieldPath {
@@ -116,6 +137,15 @@ impl FieldPath {
116137
}
117138
}
118139

140+
impl fmt::Display for FieldPath {
141+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
142+
self.register.fmt(f)?;
143+
f.write_str(".")?;
144+
f.write_str(&self.name)?;
145+
Ok(())
146+
}
147+
}
148+
119149
/// Path to `enumeratedValues` element
120150
#[derive(Clone, Debug, PartialEq, Hash, Eq)]
121151
pub struct EnumPath {
@@ -141,6 +171,15 @@ impl EnumPath {
141171
}
142172
}
143173

174+
impl fmt::Display for EnumPath {
175+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
176+
self.field.fmt(f)?;
177+
f.write_str(".")?;
178+
f.write_str(&self.name)?;
179+
Ok(())
180+
}
181+
}
182+
144183
#[derive(Clone, Debug, Default)]
145184
pub struct Index<'a> {
146185
pub peripherals: HashMap<BlockPath, &'a Peripheral>,

0 commit comments

Comments
 (0)