@@ -4,32 +4,33 @@ use crate::{
4
4
model:: Model ,
5
5
util:: parse_csv_line,
6
6
Result ,
7
+
7
8
} ;
8
9
9
10
10
11
#[ cfg( feature = "runtime-async-std" ) ]
11
12
use async_std:: {
12
- fs:: File as asyncFile ,
13
+ fs:: File as file ,
13
14
io:: prelude:: * ,
14
- io:: { BufReader as asyncBufReader , Error as asyncIoError , ErrorKind as asyncErrorKind } ,
15
- path:: Path as asyncPath ,
15
+ io:: { BufReader as ioBufReader , Error as ioError , ErrorKind as ioErrorKind } ,
16
+ path:: Path as ioPath ,
16
17
prelude:: * ,
17
18
} ;
18
19
20
+
19
21
#[ cfg( feature = "runtime-tokio" ) ]
20
22
use std:: {
21
- io:: { Error as tokioIoError , ErrorKind as tokioErrorKind } ,
22
- path:: Path as tokioPath ,
23
+ io:: { Error as ioError , ErrorKind as ioErrorKind } ,
24
+ path:: Path as ioPath ,
23
25
} ;
24
26
#[ cfg( feature = "runtime-tokio" ) ]
25
27
use tokio:: {
26
- fs:: File as tokioFile ,
27
- io:: { AsyncBufReadExt , AsyncWriteExt , BufReader as tokioBufReader } ,
28
+ fs:: File as file ,
29
+ io:: { AsyncBufReadExt , AsyncWriteExt , BufReader as ioBufReader } ,
28
30
} ;
29
31
30
- use async_trait:: async_trait;
31
32
32
- use std :: convert :: AsRef ;
33
+ use async_trait :: async_trait ;
33
34
use std:: fmt:: Write ;
34
35
35
36
pub struct FileAdapter < P > {
@@ -43,7 +44,7 @@ type LoadFilteredPolicyFileHandler<'a> =
43
44
44
45
impl < P > FileAdapter < P >
45
46
where
46
- P : AsRef < tokioPath > + Send + Sync ,
47
+ P : AsRef < ioPath > + Send + Sync ,
47
48
{
48
49
pub fn new ( p : P ) -> FileAdapter < P > {
49
50
FileAdapter {
64
65
m : & mut dyn Model ,
65
66
handler : LoadPolicyFileHandler ,
66
67
) -> Result < ( ) > {
67
- let f = tokioFile :: open ( & self . file_path ) . await ?;
68
- let mut lines = tokioBufReader :: new ( f) . lines ( ) ;
68
+ let f = file :: open ( & self . file_path ) . await ?;
69
+ let mut lines = ioBufReader :: new ( f) . lines ( ) ;
69
70
#[ cfg( feature = "runtime-async-std" ) ]
70
71
while let Some ( line) = lines. next ( ) . await {
71
72
handler ( line?, m)
85
86
filter : Filter < ' a > ,
86
87
handler : LoadFilteredPolicyFileHandler < ' a > ,
87
88
) -> Result < bool > {
88
- let f = tokioFile :: open ( & self . file_path ) . await ?;
89
- let mut lines = tokioBufReader :: new ( f) . lines ( ) ;
89
+ let f = file :: open ( & self . file_path ) . await ?;
90
+ let mut lines = ioBufReader :: new ( f) . lines ( ) ;
90
91
91
92
let mut is_filtered = false ;
92
93
#[ cfg( feature = "runtime-async-std" ) ]
@@ -107,7 +108,7 @@ where
107
108
}
108
109
109
110
async fn save_policy_file ( & self , text : String ) -> Result < ( ) > {
110
- let mut file = tokioFile :: create ( & self . file_path ) . await ?;
111
+ let mut file = file :: create ( & self . file_path ) . await ?;
111
112
file. write_all ( text. as_bytes ( ) ) . await ?;
112
113
Ok ( ( ) )
113
114
}
@@ -116,7 +117,7 @@ where
116
117
#[ async_trait]
117
118
impl < P > Adapter for FileAdapter < P >
118
119
where
119
- P : AsRef < tokioPath > + Send + Sync ,
120
+ P : AsRef < ioPath > + Send + Sync ,
120
121
{
121
122
async fn load_policy ( & mut self , m : & mut dyn Model ) -> Result < ( ) > {
122
123
self . is_filtered = false ;
@@ -138,8 +139,8 @@ where
138
139
139
140
async fn save_policy ( & mut self , m : & mut dyn Model ) -> Result < ( ) > {
140
141
if self . file_path . as_ref ( ) . as_os_str ( ) . is_empty ( ) {
141
- return Err ( tokioIoError :: new (
142
- tokioErrorKind :: Other ,
142
+ return Err ( ioError :: new (
143
+ ioErrorKind :: Other ,
143
144
"save policy failed, file path is empty" ,
144
145
)
145
146
. into ( ) ) ;
0 commit comments