@@ -29,11 +29,15 @@ pub(crate) enum TypeVisibility {
29
29
#[ derive( Debug , Copy , Clone ) ]
30
30
#[ repr( usize ) ]
31
31
pub ( crate ) enum SortBy {
32
- Rid = 0 ,
33
- Kind = 1 ,
34
- ConcreteType = 2 ,
35
- Target = 3 ,
36
- Total = 4 ,
32
+ Id = 0 ,
33
+ ParentId = 1 ,
34
+ Kind = 2 ,
35
+ Total = 3 ,
36
+ Target = 4 ,
37
+ ConcreteType = 5 ,
38
+ Visibility = 6 ,
39
+ Location = 7 ,
40
+ Attributes = 8 ,
37
41
}
38
42
39
43
#[ derive( Debug ) ]
@@ -71,27 +75,48 @@ struct ResourceStats {
71
75
72
76
impl Default for SortBy {
73
77
fn default ( ) -> Self {
74
- Self :: Rid
78
+ Self :: Id
75
79
}
76
80
}
77
81
78
82
impl SortBy {
79
83
pub fn sort ( & self , now : SystemTime , resources : & mut [ ResourceRef ] ) {
80
84
match self {
81
- Self :: Rid => {
85
+ Self :: Id => {
82
86
resources. sort_unstable_by_key ( |resource| resource. upgrade ( ) . map ( |r| r. borrow ( ) . id ) )
83
87
}
88
+ Self :: ParentId => resources. sort_unstable_by_key ( |resource| {
89
+ resource. upgrade ( ) . map ( |r| r. borrow ( ) . parent_id . clone ( ) )
90
+ } ) ,
84
91
Self :: Kind => resources. sort_unstable_by_key ( |resource| {
85
92
resource. upgrade ( ) . map ( |r| r. borrow ( ) . kind . clone ( ) )
86
93
} ) ,
94
+ Self :: Total => resources
95
+ . sort_unstable_by_key ( |resource| resource. upgrade ( ) . map ( |r| r. borrow ( ) . total ( now) ) ) ,
96
+ Self :: Target => resources. sort_unstable_by_key ( |resource| {
97
+ resource. upgrade ( ) . map ( |r| r. borrow ( ) . target . clone ( ) )
98
+ } ) ,
87
99
Self :: ConcreteType => resources. sort_unstable_by_key ( |resource| {
88
100
resource. upgrade ( ) . map ( |r| r. borrow ( ) . concrete_type . clone ( ) )
89
101
} ) ,
90
- Self :: Target => resources. sort_unstable_by_key ( |resource| {
91
- resource. upgrade ( ) . map ( |r| r. borrow ( ) . target . clone ( ) )
102
+ Self :: Visibility => resources
103
+ . sort_unstable_by_key ( |resource| resource. upgrade ( ) . map ( |r| r. borrow ( ) . visibility ) ) ,
104
+ Self :: Location => resources. sort_unstable_by_key ( |resource| {
105
+ resource. upgrade ( ) . map ( |r| r. borrow ( ) . location . clone ( ) )
106
+ } ) ,
107
+ Self :: Attributes => resources. sort_unstable_by_key ( |resource| {
108
+ resource. upgrade ( ) . and_then ( |r| {
109
+ // FIXME - we are taking only the key of the first attribute as sorting key here.
110
+ // Instead, attributes should probably be parsed and sorted according to their actual values.
111
+ //
112
+ // See https://github.com/tokio-rs/console/issues/496
113
+ r. borrow ( )
114
+ . formatted_attributes ( )
115
+ . first ( )
116
+ . and_then ( |a| a. first ( ) )
117
+ . map ( |key| key. content . clone ( ) )
118
+ } )
92
119
} ) ,
93
- Self :: Total => resources
94
- . sort_unstable_by_key ( |resource| resource. upgrade ( ) . map ( |r| r. borrow ( ) . total ( now) ) ) ,
95
120
}
96
121
}
97
122
}
@@ -100,11 +125,15 @@ impl TryFrom<usize> for SortBy {
100
125
type Error = ( ) ;
101
126
fn try_from ( idx : usize ) -> Result < Self , Self :: Error > {
102
127
match idx {
103
- idx if idx == Self :: Rid as usize => Ok ( Self :: Rid ) ,
128
+ idx if idx == Self :: Id as usize => Ok ( Self :: Id ) ,
129
+ idx if idx == Self :: ParentId as usize => Ok ( Self :: ParentId ) ,
104
130
idx if idx == Self :: Kind as usize => Ok ( Self :: Kind ) ,
105
- idx if idx == Self :: ConcreteType as usize => Ok ( Self :: ConcreteType ) ,
106
- idx if idx == Self :: Target as usize => Ok ( Self :: Target ) ,
107
131
idx if idx == Self :: Total as usize => Ok ( Self :: Total ) ,
132
+ idx if idx == Self :: Target as usize => Ok ( Self :: Target ) ,
133
+ idx if idx == Self :: ConcreteType as usize => Ok ( Self :: ConcreteType ) ,
134
+ idx if idx == Self :: Visibility as usize => Ok ( Self :: Visibility ) ,
135
+ idx if idx == Self :: Location as usize => Ok ( Self :: Location ) ,
136
+ idx if idx == Self :: Attributes as usize => Ok ( Self :: Attributes ) ,
108
137
_ => Err ( ( ) ) ,
109
138
}
110
139
}
0 commit comments