Skip to content

Commit 081a30d

Browse files
caofengyicaofengyi
caofengyi
authored and
caofengyi
committed
Fix : #6
1 parent ea50240 commit 081a30d

File tree

3 files changed

+36
-35
lines changed

3 files changed

+36
-35
lines changed

src/adapter/file_adapter.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,33 @@ use crate::{
44
model::Model,
55
util::parse_csv_line,
66
Result,
7+
78
};
89

910

1011
#[cfg(feature = "runtime-async-std")]
1112
use async_std::{
12-
fs::File as asyncFile,
13+
fs::File as file,
1314
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,
1617
prelude::*,
1718
};
1819

20+
1921
#[cfg(feature = "runtime-tokio")]
2022
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,
2325
};
2426
#[cfg(feature = "runtime-tokio")]
2527
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},
2830
};
2931

30-
use async_trait::async_trait;
3132

32-
use std::convert::AsRef;
33+
use async_trait::async_trait;
3334
use std::fmt::Write;
3435

3536
pub struct FileAdapter<P> {
@@ -43,7 +44,7 @@ type LoadFilteredPolicyFileHandler<'a> =
4344

4445
impl<P> FileAdapter<P>
4546
where
46-
P: AsRef<tokioPath> + Send + Sync,
47+
P: AsRef<ioPath> + Send + Sync,
4748
{
4849
pub fn new(p: P) -> FileAdapter<P> {
4950
FileAdapter {
@@ -64,8 +65,8 @@ where
6465
m: &mut dyn Model,
6566
handler: LoadPolicyFileHandler,
6667
) -> 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();
6970
#[cfg(feature = "runtime-async-std")]
7071
while let Some(line) = lines.next().await {
7172
handler(line?, m)
@@ -85,8 +86,8 @@ where
8586
filter: Filter<'a>,
8687
handler: LoadFilteredPolicyFileHandler<'a>,
8788
) -> 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();
9091

9192
let mut is_filtered = false;
9293
#[cfg(feature = "runtime-async-std")]
@@ -107,7 +108,7 @@ where
107108
}
108109

109110
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?;
111112
file.write_all(text.as_bytes()).await?;
112113
Ok(())
113114
}
@@ -116,7 +117,7 @@ where
116117
#[async_trait]
117118
impl<P> Adapter for FileAdapter<P>
118119
where
119-
P: AsRef<tokioPath> + Send + Sync,
120+
P: AsRef<ioPath> + Send + Sync,
120121
{
121122
async fn load_policy(&mut self, m: &mut dyn Model) -> Result<()> {
122123
self.is_filtered = false;
@@ -138,8 +139,8 @@ where
138139

139140
async fn save_policy(&mut self, m: &mut dyn Model) -> Result<()> {
140141
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,
143144
"save policy failed, file path is empty",
144145
)
145146
.into());

src/config.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ use crate::Result;
33
#[cfg(feature = "runtime-async-std")]
44
use async_std::{
55
io::prelude::*,
6-
io::{BufReader, Cursor, Error as IoError, ErrorKind},
6+
io::{BufReader as ioBufReader, Cursor, Error as ioError, ioErrorKind},
77
};
88

99
#[cfg(all(feature = "runtime-async-std", not(target_arch = "wasm32")))]
10-
use async_std::{fs::File, path::Path};
10+
use async_std::{fs::File as file, path::Path as ioPath};
1111

1212
#[cfg(feature = "runtime-tokio")]
13-
use std::{io::Cursor as tokioCursor, path::Path as tokioPath};
13+
use std::{io::Cursor as tokioCursor, path::Path as ioPath};
1414
#[cfg(feature = "runtime-tokio")]
1515
use tokio::io::{
16-
AsyncBufReadExt, AsyncReadExt, BufReader as tokioBufReader, Error as tokioIoError, ErrorKind as tokioErrorKind,
16+
AsyncBufReadExt, AsyncReadExt, BufReader as ioBufReader, Error as ioError, ErrorKind as ioErrorKind,
1717
};
1818

1919
#[cfg(all(feature = "runtime-tokio", not(target_arch = "wasm32")))]
20-
use tokio::fs::File as tokioFile;
20+
use tokio::fs::File as file;
2121

2222
use std::collections::HashMap;
2323

@@ -32,7 +32,7 @@ pub(crate) struct Config {
3232

3333
impl Config {
3434
#[cfg(not(target_arch = "wasm32"))]
35-
pub(crate) async fn from_file<P: AsRef<tokioPath>>(p: P) -> Result<Self> {
35+
pub(crate) async fn from_file<P: AsRef<ioPath>>(p: P) -> Result<Self> {
3636
let mut c = Config {
3737
data: HashMap::new(),
3838
};
@@ -46,25 +46,25 @@ impl Config {
4646
data: HashMap::new(),
4747
};
4848

49-
c.parse_buffer(&mut tokioBufReader::new(tokioCursor::new(s.as_ref().as_bytes())))
49+
c.parse_buffer(&mut ioBufReader::new(tokioCursor::new(s.as_ref().as_bytes())))
5050
.await?;
5151
Ok(c)
5252
}
5353

5454
#[cfg(not(target_arch = "wasm32"))]
55-
async fn parse<P: AsRef<tokioPath>>(&mut self, p: P) -> Result<()> {
56-
let mut f = tokioFile::open(p).await?;
55+
async fn parse<P: AsRef<ioPath>>(&mut self, p: P) -> Result<()> {
56+
let mut f = file::open(p).await?;
5757
let mut c = Vec::new();
5858
f.read_to_end(&mut c).await?;
5959

60-
let mut reader: tokioBufReader<tokioCursor<&[u8]>> =
61-
tokioBufReader::new(tokioCursor::new(&c));
60+
let mut reader: ioBufReader<tokioCursor<&[u8]>> =
61+
ioBufReader::new(tokioCursor::new(&c));
6262
self.parse_buffer(&mut reader).await
6363
}
6464

6565
async fn parse_buffer(
6666
&mut self,
67-
reader: &mut tokioBufReader<tokioCursor<&[u8]>>,
67+
reader: &mut ioBufReader<tokioCursor<&[u8]>>,
6868
) -> Result<()> {
6969
let mut section = String::new();
7070

@@ -122,8 +122,8 @@ impl Config {
122122
.collect();
123123

124124
if option_val.len() != 2 {
125-
return Err(tokioIoError::new(
126-
tokioErrorKind::Other,
125+
return Err(ioError::new(
126+
ioErrorKind::Other,
127127
format!("parse content error, line={}", line),
128128
)
129129
.into());

src/model/default_model.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ use parking_lot::RwLock;
1414
use ritelinked::{LinkedHashMap, LinkedHashSet};
1515

1616
#[cfg(all(feature = "runtime-async-std", not(target_arch = "wasm32")))]
17-
use async_std::path::Path;
17+
use async_std::path::Path as ioPath;
1818

1919
#[cfg(feature = "runtime-tokio")]
20-
use std::path::Path as tokioPath;
20+
use std::path::Path as ioPath;
2121

2222
use std::{collections::HashMap, sync::Arc};
2323

@@ -28,7 +28,7 @@ pub struct DefaultModel {
2828

2929
impl DefaultModel {
3030
#[cfg(not(target_arch = "wasm32"))]
31-
pub async fn from_file<P: AsRef<tokioPath>>(p: P) -> Result<DefaultModel> {
31+
pub async fn from_file<P: AsRef<ioPath>>(p: P) -> Result<DefaultModel> {
3232
let cfg = Config::from_file(p).await?;
3333

3434
let mut model = DefaultModel::default();

0 commit comments

Comments
 (0)