@@ -90,19 +90,17 @@ fn packages(
9090 & format ! ( "{pkg_manager:?}" ) . to_lowercase ( ) ,
9191 )
9292 . unwrap_or ( 0 ) ,
93- PackageManager :: Rpm => match get_macchina_package_count (
93+ PackageManager :: Rpm => get_macchina_package_count (
9494 macchina_package_count,
9595 & format ! ( "{pkg_manager:?}" ) . to_lowercase ( ) ,
96- ) {
97- Some ( count) => count,
98- None => {
99- if !skip_slow {
100- run_and_count_lines ( "rpm" , & [ "-qa" ] )
101- } else {
102- 0
103- }
96+ )
97+ . unwrap_or_else ( || {
98+ if !skip_slow {
99+ run_and_count_lines ( "rpm" , & [ "-qa" ] )
100+ } else {
101+ 0
104102 }
105- } ,
103+ } ) ,
106104 PackageManager :: Guix => run_and_count_lines ( "guix" , & [ "package" , "--list-installed" ] ) ,
107105 PackageManager :: Crux => {
108106 if check_if_command_exists ( "crux" ) {
@@ -139,37 +137,31 @@ pub fn user_at_hostname(
139137 username_override : & Option < String > ,
140138 hostname_override : & Option < String > ,
141139) -> Option < String > {
142- let username = match username_override {
143- Some ( username) => Ok ( username. to_string ( ) ) ,
144- None => general_readout. username ( ) ,
145- } ;
146- let hostname = match hostname_override {
147- Some ( hostname) => Ok ( hostname. to_string ( ) ) ,
148- None => general_readout. hostname ( ) ,
149- } ;
150- if username. is_err ( ) || hostname. is_err ( ) {
151- None
152- } else {
153- Some ( format ! (
154- "{}@{}" ,
155- username. unwrap_or_default( ) ,
156- hostname. unwrap_or_default( )
157- ) )
140+ let username = username_override
141+ . to_owned ( )
142+ . or_else ( || general_readout. username ( ) . ok ( ) ) ;
143+ let hostname = hostname_override
144+ . to_owned ( )
145+ . or_else ( || general_readout. hostname ( ) . ok ( ) ) ;
146+
147+ if let ( Some ( username) , Some ( hostname) ) = ( username, hostname) {
148+ return Some ( format ! ( "{username}@{hostname}" ) ) ;
158149 }
150+ None
159151}
160152
161153pub fn memory ( memory_readout : & MemoryReadout ) -> Option < String > {
162154 let total_memory = memory_readout. total ( ) ;
163155 let used_memory = memory_readout. used ( ) ;
164- if total_memory. is_err ( ) || used_memory. is_err ( ) {
165- None
166- } else {
167- Some ( format ! (
156+
157+ if let ( Ok ( total_memory) , Ok ( used_memory) ) = ( total_memory, used_memory) {
158+ return Some ( format ! (
168159 "{}M / {}M" ,
169- used_memory. unwrap ( ) / 1024 ,
170- total_memory. unwrap ( ) / 1024
171- ) )
160+ used_memory / 1024 ,
161+ total_memory / 1024
162+ ) ) ;
172163 }
164+ None
173165}
174166
175167pub fn cpu ( general_readout : & GeneralReadout ) -> Option < String > {
@@ -236,7 +228,7 @@ pub fn seconds_to_string(seconds: usize) -> String {
236228}
237229
238230pub fn uptime ( general_readout : & GeneralReadout ) -> Option < String > {
239- Some ( seconds_to_string ( general_readout. uptime ( ) . ok ( ) ? ) )
231+ general_readout. uptime ( ) . ok ( ) . map ( seconds_to_string )
240232}
241233
242234pub fn host ( general_readout : & GeneralReadout ) -> Option < String > {
@@ -439,4 +431,3 @@ mod tests {
439431 assert_eq ! ( seconds_to_string( 90060 ) , "1d 1h 1m" . to_string( ) ) ;
440432 }
441433}
442-
0 commit comments