@@ -29,11 +29,15 @@ pub(crate) enum TypeVisibility {
2929#[ derive( Debug , Copy , Clone ) ]
3030#[ repr( usize ) ]
3131pub ( 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 ,
3741}
3842
3943#[ derive( Debug ) ]
@@ -71,27 +75,48 @@ struct ResourceStats {
7175
7276impl Default for SortBy {
7377 fn default ( ) -> Self {
74- Self :: Rid
78+ Self :: Id
7579 }
7680}
7781
7882impl SortBy {
7983 pub fn sort ( & self , now : SystemTime , resources : & mut [ ResourceRef ] ) {
8084 match self {
81- Self :: Rid => {
85+ Self :: Id => {
8286 resources. sort_unstable_by_key ( |resource| resource. upgrade ( ) . map ( |r| r. borrow ( ) . id ) )
8387 }
88+ Self :: ParentId => resources. sort_unstable_by_key ( |resource| {
89+ resource. upgrade ( ) . map ( |r| r. borrow ( ) . parent_id . clone ( ) )
90+ } ) ,
8491 Self :: Kind => resources. sort_unstable_by_key ( |resource| {
8592 resource. upgrade ( ) . map ( |r| r. borrow ( ) . kind . clone ( ) )
8693 } ) ,
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+ } ) ,
8799 Self :: ConcreteType => resources. sort_unstable_by_key ( |resource| {
88100 resource. upgrade ( ) . map ( |r| r. borrow ( ) . concrete_type . clone ( ) )
89101 } ) ,
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+ } )
92119 } ) ,
93- Self :: Total => resources
94- . sort_unstable_by_key ( |resource| resource. upgrade ( ) . map ( |r| r. borrow ( ) . total ( now) ) ) ,
95120 }
96121 }
97122}
@@ -100,11 +125,15 @@ impl TryFrom<usize> for SortBy {
100125 type Error = ( ) ;
101126 fn try_from ( idx : usize ) -> Result < Self , Self :: Error > {
102127 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 ) ,
104130 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 ) ,
107131 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 ) ,
108137 _ => Err ( ( ) ) ,
109138 }
110139 }
0 commit comments