@@ -3,14 +3,14 @@ use core::ops::{Deref, DerefMut};
3
3
4
4
/// A single SVD instance or array of instances
5
5
#[ derive( Clone , Debug , PartialEq ) ]
6
- pub enum SingleArray < T > {
6
+ pub enum MaybeArray < T > {
7
7
/// A single instance
8
8
Single ( T ) ,
9
9
/// An array of instances
10
10
Array ( T , DimElement ) ,
11
11
}
12
12
13
- impl < T > Deref for SingleArray < T > {
13
+ impl < T > Deref for MaybeArray < T > {
14
14
type Target = T ;
15
15
16
16
fn deref ( & self ) -> & T {
@@ -21,7 +21,7 @@ impl<T> Deref for SingleArray<T> {
21
21
}
22
22
}
23
23
24
- impl < T > DerefMut for SingleArray < T > {
24
+ impl < T > DerefMut for MaybeArray < T > {
25
25
fn deref_mut ( & mut self ) -> & mut T {
26
26
match self {
27
27
Self :: Single ( info) => info,
@@ -30,7 +30,7 @@ impl<T> DerefMut for SingleArray<T> {
30
30
}
31
31
}
32
32
33
- impl < T > SingleArray < T > {
33
+ impl < T > MaybeArray < T > {
34
34
/// Return `true` if instance is single
35
35
pub const fn is_single ( & self ) -> bool {
36
36
matches ! ( self , Self :: Single ( _) )
@@ -41,7 +41,7 @@ impl<T> SingleArray<T> {
41
41
}
42
42
}
43
43
44
- impl < T > Name for SingleArray < T >
44
+ impl < T > Name for MaybeArray < T >
45
45
where
46
46
T : Name ,
47
47
{
50
50
}
51
51
}
52
52
53
+ /// Return list of names of instances in array
54
+ pub fn names < ' a , T : Name > ( info : & ' a T , dim : & ' a DimElement ) -> impl Iterator < Item = String > + ' a {
55
+ let name = info. name ( ) ;
56
+ dim. indexes ( )
57
+ . map ( move |i| name. replace ( "[%s]" , & i) . replace ( "%s" , & i) )
58
+ }
59
+
53
60
#[ cfg( feature = "serde" ) ]
54
61
mod ser_de {
55
62
use super :: * ;
@@ -71,7 +78,7 @@ mod ser_de {
71
78
info : T ,
72
79
}
73
80
74
- impl < T > Serialize for SingleArray < T >
81
+ impl < T > Serialize for MaybeArray < T >
75
82
where
76
83
T : Serialize ,
77
84
{
@@ -86,7 +93,7 @@ mod ser_de {
86
93
}
87
94
}
88
95
89
- impl < ' de , T > Deserialize < ' de > for SingleArray < T >
96
+ impl < ' de , T > Deserialize < ' de > for MaybeArray < T >
90
97
where
91
98
T : Deserialize < ' de > ,
92
99
{
0 commit comments