File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33// For the full copyright and license information, please view the LICENSE
44// file that was distributed with this source code.
55
6- use std:: {
7- cmp:: Ordering ,
8- fs,
9- io:: { Error , ErrorKind } ,
10- } ;
6+ use std:: io:: Error ;
7+ use std:: { cmp:: Ordering , fs, io:: ErrorKind } ;
8+ use uucore:: error:: { UError , UResult , USimpleError } ;
119
1210#[ derive( Debug , Default ) ]
1311pub struct SlabInfo {
@@ -18,10 +16,22 @@ pub struct SlabInfo {
1816impl SlabInfo {
1917 // parse slabinfo from /proc/slabinfo
2018 // need root permission
21- pub fn new ( ) -> Result < SlabInfo , Error > {
22- let content = fs:: read_to_string ( "/proc/slabinfo" ) ?;
19+ pub fn new ( ) -> UResult < SlabInfo > {
20+ let error_wrapper = |e : Error | {
21+ USimpleError :: new (
22+ 1 ,
23+ format ! (
24+ "Unable to create slabinfo structure: {}" ,
25+ Box :: <dyn UError >:: from( e) // We need Display impl of UError
26+ ) ,
27+ )
28+ } ;
29+
30+ let content = fs:: read_to_string ( "/proc/slabinfo" ) . map_err ( error_wrapper) ?;
2331
24- Self :: parse ( & content) . ok_or ( ErrorKind :: Unsupported . into ( ) )
32+ Self :: parse ( & content)
33+ . ok_or ( ErrorKind :: Unsupported . into ( ) )
34+ . map_err ( error_wrapper)
2535 }
2636
2737 pub fn parse ( content : & str ) -> Option < SlabInfo > {
You can’t perform that action at this time.
0 commit comments