1
1
//! Provides [expand] method to convert arrays, clusters and derived items in regular instances
2
2
3
3
use anyhow:: { anyhow, Result } ;
4
- use std:: { collections:: HashMap , fmt, mem:: take, ops:: Deref } ;
4
+ use std:: { collections:: HashMap , fmt, mem:: take, ops:: Deref , rc :: Rc } ;
5
5
use svd_rs:: {
6
6
array:: names, cluster, field, peripheral, register, Cluster , ClusterInfo , DeriveFrom , Device ,
7
7
EnumeratedValues , Field , Peripheral , Register , RegisterCluster , RegisterProperties ,
@@ -10,23 +10,23 @@ use svd_rs::{
10
10
/// Path to `peripheral` or `cluster` element
11
11
#[ derive( Clone , Debug , PartialEq , Hash , Eq ) ]
12
12
pub struct BlockPath {
13
- pub peripheral : String ,
14
- pub path : Vec < String > ,
13
+ pub peripheral : Rc < str > ,
14
+ pub path : Vec < Rc < str > > ,
15
15
}
16
16
17
17
impl BlockPath {
18
- pub fn new ( p : impl Into < String > ) -> Self {
18
+ pub fn new ( p : impl Into < Rc < str > > ) -> Self {
19
19
Self {
20
20
peripheral : p. into ( ) ,
21
21
path : Vec :: new ( ) ,
22
22
}
23
23
}
24
- pub fn new_cluster ( & self , name : impl Into < String > ) -> Self {
24
+ pub fn new_cluster ( & self , name : impl Into < Rc < str > > ) -> Self {
25
25
let mut child = self . clone ( ) ;
26
26
child. path . push ( name. into ( ) ) ;
27
27
child
28
28
}
29
- pub fn new_register ( & self , name : impl Into < String > ) -> RegisterPath {
29
+ pub fn new_register ( & self , name : impl Into < Rc < str > > ) -> RegisterPath {
30
30
RegisterPath :: new ( self . clone ( ) , name)
31
31
}
32
32
pub fn parse_str ( s : & str ) -> ( Option < Self > , & str ) {
@@ -44,7 +44,7 @@ impl BlockPath {
44
44
} ;
45
45
( block, name)
46
46
}
47
- pub fn name ( & self ) -> & String {
47
+ pub fn name ( & self ) -> & str {
48
48
self . path . last ( ) . unwrap ( )
49
49
}
50
50
pub fn parent ( & self ) -> Option < Self > {
@@ -91,17 +91,17 @@ impl fmt::Display for BlockPath {
91
91
#[ derive( Clone , Debug , PartialEq , Hash , Eq ) ]
92
92
pub struct RegisterPath {
93
93
pub block : BlockPath ,
94
- pub name : String ,
94
+ pub name : Rc < str > ,
95
95
}
96
96
97
97
impl RegisterPath {
98
- pub fn new ( block : BlockPath , name : impl Into < String > ) -> Self {
98
+ pub fn new ( block : BlockPath , name : impl Into < Rc < str > > ) -> Self {
99
99
Self {
100
100
block,
101
101
name : name. into ( ) ,
102
102
}
103
103
}
104
- pub fn new_field ( & self , name : impl Into < String > ) -> FieldPath {
104
+ pub fn new_field ( & self , name : impl Into < Rc < str > > ) -> FieldPath {
105
105
FieldPath :: new ( self . clone ( ) , name)
106
106
}
107
107
pub fn parse_str ( s : & str ) -> ( Option < BlockPath > , & str ) {
@@ -110,7 +110,7 @@ impl RegisterPath {
110
110
pub fn parse_vec ( v : Vec < & str > ) -> ( Option < BlockPath > , & str ) {
111
111
BlockPath :: parse_vec ( v)
112
112
}
113
- pub fn peripheral ( & self ) -> & String {
113
+ pub fn peripheral ( & self ) -> & str {
114
114
& self . block . peripheral
115
115
}
116
116
}
@@ -138,17 +138,17 @@ impl fmt::Display for RegisterPath {
138
138
#[ derive( Clone , Debug , PartialEq , Hash , Eq ) ]
139
139
pub struct FieldPath {
140
140
pub register : RegisterPath ,
141
- pub name : String ,
141
+ pub name : Rc < str > ,
142
142
}
143
143
144
144
impl FieldPath {
145
- pub fn new ( register : RegisterPath , name : impl Into < String > ) -> Self {
145
+ pub fn new ( register : RegisterPath , name : impl Into < Rc < str > > ) -> Self {
146
146
Self {
147
147
register,
148
148
name : name. into ( ) ,
149
149
}
150
150
}
151
- pub fn new_enum ( & self , name : impl Into < String > ) -> EnumPath {
151
+ pub fn new_enum ( & self , name : impl Into < Rc < str > > ) -> EnumPath {
152
152
EnumPath :: new ( self . clone ( ) , name)
153
153
}
154
154
pub fn parse_str ( s : & str ) -> ( Option < RegisterPath > , & str ) {
@@ -170,7 +170,7 @@ impl FieldPath {
170
170
pub fn register ( & self ) -> & RegisterPath {
171
171
& self . register
172
172
}
173
- pub fn peripheral ( & self ) -> & String {
173
+ pub fn peripheral ( & self ) -> & str {
174
174
self . register . peripheral ( )
175
175
}
176
176
}
@@ -198,11 +198,11 @@ impl fmt::Display for FieldPath {
198
198
#[ derive( Clone , Debug , PartialEq , Hash , Eq ) ]
199
199
pub struct EnumPath {
200
200
pub field : FieldPath ,
201
- pub name : String ,
201
+ pub name : Rc < str > ,
202
202
}
203
203
204
204
impl EnumPath {
205
- pub fn new ( field : FieldPath , name : impl Into < String > ) -> Self {
205
+ pub fn new ( field : FieldPath , name : impl Into < Rc < str > > ) -> Self {
206
206
Self {
207
207
field,
208
208
name : name. into ( ) ,
@@ -214,7 +214,7 @@ impl EnumPath {
214
214
pub fn register ( & self ) -> & RegisterPath {
215
215
& self . field . register
216
216
}
217
- pub fn peripheral ( & self ) -> & String {
217
+ pub fn peripheral ( & self ) -> & str {
218
218
self . field . peripheral ( )
219
219
}
220
220
}
0 commit comments