11//! Provides [expand] method to convert arrays, clusters and derived items in regular instances
22
33use 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 } ;
55use svd_rs:: {
66 array:: names, cluster, field, peripheral, register, Cluster , ClusterInfo , DeriveFrom , Device ,
77 EnumeratedValues , Field , Peripheral , Register , RegisterCluster , RegisterProperties ,
@@ -10,23 +10,23 @@ use svd_rs::{
1010/// Path to `peripheral` or `cluster` element
1111#[ derive( Clone , Debug , PartialEq , Hash , Eq ) ]
1212pub struct BlockPath {
13- pub peripheral : String ,
14- pub path : Vec < String > ,
13+ pub peripheral : Rc < str > ,
14+ pub path : Vec < Rc < str > > ,
1515}
1616
1717impl BlockPath {
18- pub fn new ( p : impl Into < String > ) -> Self {
18+ pub fn new ( p : impl Into < Rc < str > > ) -> Self {
1919 Self {
2020 peripheral : p. into ( ) ,
2121 path : Vec :: new ( ) ,
2222 }
2323 }
24- pub fn new_cluster ( & self , name : impl Into < String > ) -> Self {
24+ pub fn new_cluster ( & self , name : impl Into < Rc < str > > ) -> Self {
2525 let mut child = self . clone ( ) ;
2626 child. path . push ( name. into ( ) ) ;
2727 child
2828 }
29- pub fn new_register ( & self , name : impl Into < String > ) -> RegisterPath {
29+ pub fn new_register ( & self , name : impl Into < Rc < str > > ) -> RegisterPath {
3030 RegisterPath :: new ( self . clone ( ) , name)
3131 }
3232 pub fn parse_str ( s : & str ) -> ( Option < Self > , & str ) {
@@ -44,7 +44,7 @@ impl BlockPath {
4444 } ;
4545 ( block, name)
4646 }
47- pub fn name ( & self ) -> & String {
47+ pub fn name ( & self ) -> & str {
4848 self . path . last ( ) . unwrap ( )
4949 }
5050 pub fn parent ( & self ) -> Option < Self > {
@@ -91,17 +91,17 @@ impl fmt::Display for BlockPath {
9191#[ derive( Clone , Debug , PartialEq , Hash , Eq ) ]
9292pub struct RegisterPath {
9393 pub block : BlockPath ,
94- pub name : String ,
94+ pub name : Rc < str > ,
9595}
9696
9797impl RegisterPath {
98- pub fn new ( block : BlockPath , name : impl Into < String > ) -> Self {
98+ pub fn new ( block : BlockPath , name : impl Into < Rc < str > > ) -> Self {
9999 Self {
100100 block,
101101 name : name. into ( ) ,
102102 }
103103 }
104- pub fn new_field ( & self , name : impl Into < String > ) -> FieldPath {
104+ pub fn new_field ( & self , name : impl Into < Rc < str > > ) -> FieldPath {
105105 FieldPath :: new ( self . clone ( ) , name)
106106 }
107107 pub fn parse_str ( s : & str ) -> ( Option < BlockPath > , & str ) {
@@ -110,7 +110,7 @@ impl RegisterPath {
110110 pub fn parse_vec ( v : Vec < & str > ) -> ( Option < BlockPath > , & str ) {
111111 BlockPath :: parse_vec ( v)
112112 }
113- pub fn peripheral ( & self ) -> & String {
113+ pub fn peripheral ( & self ) -> & str {
114114 & self . block . peripheral
115115 }
116116}
@@ -138,17 +138,17 @@ impl fmt::Display for RegisterPath {
138138#[ derive( Clone , Debug , PartialEq , Hash , Eq ) ]
139139pub struct FieldPath {
140140 pub register : RegisterPath ,
141- pub name : String ,
141+ pub name : Rc < str > ,
142142}
143143
144144impl FieldPath {
145- pub fn new ( register : RegisterPath , name : impl Into < String > ) -> Self {
145+ pub fn new ( register : RegisterPath , name : impl Into < Rc < str > > ) -> Self {
146146 Self {
147147 register,
148148 name : name. into ( ) ,
149149 }
150150 }
151- pub fn new_enum ( & self , name : impl Into < String > ) -> EnumPath {
151+ pub fn new_enum ( & self , name : impl Into < Rc < str > > ) -> EnumPath {
152152 EnumPath :: new ( self . clone ( ) , name)
153153 }
154154 pub fn parse_str ( s : & str ) -> ( Option < RegisterPath > , & str ) {
@@ -170,7 +170,7 @@ impl FieldPath {
170170 pub fn register ( & self ) -> & RegisterPath {
171171 & self . register
172172 }
173- pub fn peripheral ( & self ) -> & String {
173+ pub fn peripheral ( & self ) -> & str {
174174 self . register . peripheral ( )
175175 }
176176}
@@ -198,11 +198,11 @@ impl fmt::Display for FieldPath {
198198#[ derive( Clone , Debug , PartialEq , Hash , Eq ) ]
199199pub struct EnumPath {
200200 pub field : FieldPath ,
201- pub name : String ,
201+ pub name : Rc < str > ,
202202}
203203
204204impl EnumPath {
205- pub fn new ( field : FieldPath , name : impl Into < String > ) -> Self {
205+ pub fn new ( field : FieldPath , name : impl Into < Rc < str > > ) -> Self {
206206 Self {
207207 field,
208208 name : name. into ( ) ,
@@ -214,7 +214,7 @@ impl EnumPath {
214214 pub fn register ( & self ) -> & RegisterPath {
215215 & self . field . register
216216 }
217- pub fn peripheral ( & self ) -> & String {
217+ pub fn peripheral ( & self ) -> & str {
218218 self . field . peripheral ( )
219219 }
220220}
0 commit comments