Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitff78cc0

Browse files
committed
refactor: use AsRef<u8> instead of &u8 for API flexibility
1 parent4d289fd commitff78cc0

File tree

6 files changed

+29
-25
lines changed

6 files changed

+29
-25
lines changed

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name ="tokio-fs-ext"
3-
version ="0.4.1"
3+
version ="0.5.0"
44
edition ="2024"
55
authors = ["xusd320"]
66
description ="Extend tokio fs to be compatible with native and wasm"

‎src/fs/wasm/file.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl File {
9191
Ok(size)
9292
}
9393

94-
pub(crate)fnwrite_with_buf(&self,buf:&[u8]) -> io::Result<u64>{
94+
pub(crate)fnwrite_with_buf(&self,buf:implAsRef<[u8]>) -> io::Result<u64>{
9595
let options =FileSystemReadWriteOptions::new();
9696
options.set_at(*self.pos.lock().unwrap()asf64);
9797
let size =self

‎src/fs/wasm/offload/client.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ impl Client {
1515
self.dispatch(|sender|FsTask::Read{ path, sender}).await
1616
}
1717

18-
pubasyncfnwrite(&self,path:implAsRef<Path>,content:&[u8]) -> io::Result<()>{
18+
pubasyncfnwrite(&self,path:implAsRef<Path>,content:implAsRef<[u8]>) -> io::Result<()>{
1919
let path = path.as_ref().into();
20-
let content = content.to_vec();
20+
let content = content.as_ref().to_vec();
2121
self.dispatch(|sender|FsTask::Write{
2222
path,
2323
sender,

‎src/fs/wasm/offload/mod.rs‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{io, path::PathBuf};
1+
use std::{io, path::Path};
22

33
use tokio::sync::mpsc;
44

@@ -20,53 +20,53 @@ pub fn split() -> (Server, Client) {
2020

2121
#[allow(async_fn_in_trait)]
2222
pubtraitFsOffload{
23-
asyncfnread(&self,path:PathBuf) -> io::Result<Vec<u8>>;
24-
asyncfnwrite(&self,path:PathBuf,content:Vec<u8>) -> io::Result<()>;
25-
asyncfnread_dir(&self,path:PathBuf) -> io::Result<ReadDir>;
26-
asyncfncreate_dir(&self,path:PathBuf) -> io::Result<()>;
27-
asyncfncreate_dir_all(&self,path:PathBuf) -> io::Result<()>;
28-
asyncfnremove_file(&self,path:PathBuf) -> io::Result<()>;
29-
asyncfnremove_dir(&self,path:PathBuf) -> io::Result<()>;
30-
asyncfnremove_dir_all(&self,path:PathBuf) -> io::Result<()>;
31-
asyncfnmetadata(&self,path:PathBuf) -> io::Result<Metadata>;
23+
asyncfnread(&self,path:implAsRef<Path>) -> io::Result<Vec<u8>>;
24+
asyncfnwrite(&self,path:implAsRef<Path>,content:implAsRef<[u8]>) -> io::Result<()>;
25+
asyncfnread_dir(&self,path:implAsRef<Path>) -> io::Result<ReadDir>;
26+
asyncfncreate_dir(&self,path:implAsRef<Path>) -> io::Result<()>;
27+
asyncfncreate_dir_all(&self,path:implAsRef<Path>) -> io::Result<()>;
28+
asyncfnremove_file(&self,path:implAsRef<Path>) -> io::Result<()>;
29+
asyncfnremove_dir(&self,path:implAsRef<Path>) -> io::Result<()>;
30+
asyncfnremove_dir_all(&self,path:implAsRef<Path>) -> io::Result<()>;
31+
asyncfnmetadata(&self,path:implAsRef<Path>) -> io::Result<Metadata>;
3232
}
3333

3434
pubstructFsOffloadDefault;
3535

3636
implFsOffloadforFsOffloadDefault{
37-
asyncfnread(&self,path:PathBuf) -> io::Result<Vec<u8>>{
37+
asyncfnread(&self,path:implAsRef<Path>) -> io::Result<Vec<u8>>{
3838
read(path).await
3939
}
4040

41-
asyncfnwrite(&self,path:PathBuf,content:Vec<u8>) -> io::Result<()>{
41+
asyncfnwrite(&self,path:implAsRef<Path>,content:implAsRef<[u8]>) -> io::Result<()>{
4242
write(path, content).await
4343
}
4444

45-
asyncfnread_dir(&self,path:PathBuf) -> io::Result<ReadDir>{
45+
asyncfnread_dir(&self,path:implAsRef<Path>) -> io::Result<ReadDir>{
4646
read_dir(path).await
4747
}
4848

49-
asyncfncreate_dir(&self,path:PathBuf) -> io::Result<()>{
49+
asyncfncreate_dir(&self,path:implAsRef<Path>) -> io::Result<()>{
5050
create_dir(path).await
5151
}
5252

53-
asyncfncreate_dir_all(&self,path:PathBuf) -> io::Result<()>{
53+
asyncfncreate_dir_all(&self,path:implAsRef<Path>) -> io::Result<()>{
5454
create_dir_all(path).await
5555
}
5656

57-
asyncfnremove_file(&self,path:PathBuf) -> io::Result<()>{
57+
asyncfnremove_file(&self,path:implAsRef<Path>) -> io::Result<()>{
5858
remove_file(path).await
5959
}
6060

61-
asyncfnremove_dir(&self,path:PathBuf) -> io::Result<()>{
61+
asyncfnremove_dir(&self,path:implAsRef<Path>) -> io::Result<()>{
6262
remove_dir(path).await
6363
}
6464

65-
asyncfnremove_dir_all(&self,path:PathBuf) -> io::Result<()>{
65+
asyncfnremove_dir_all(&self,path:implAsRef<Path>) -> io::Result<()>{
6666
remove_dir_all(path).await
6767
}
6868

69-
asyncfnmetadata(&self,path:PathBuf) -> io::Result<Metadata>{
69+
asyncfnmetadata(&self,path:implAsRef<Path>) -> io::Result<Metadata>{
7070
metadata(path).await
7171
}
7272
}

‎src/fs/wasm/offload/server.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use tokio::sync::mpsc;
22

3-
usesuper::{FsOffload,FsTask};
3+
usesuper::{FsOffload,FsOffloadDefault,FsTask};
44

55
pubstructServer{
66
pub(super)receiver: mpsc::Receiver<FsTask>,
@@ -12,4 +12,8 @@ impl Server {
1212
task.execute(&offload).await;
1313
}
1414
}
15+
16+
pubasyncfnserve_default(&mutself){
17+
self.serve(FsOffloadDefault).await
18+
}
1519
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp