Debian Codegraph @

src/fs.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/Metadata#;
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/;
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::{Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#};
5
6 use craterust-analyzer cargo sqlx-core 0.8.3 crate/::rtrust-analyzer cargo sqlx-core 0.8.3 rt/;
7
8 pub struct ReadDirrust-analyzer cargo sqlx-core 0.8.3 fs/ReadDir# {
9 innerrust-analyzer cargo sqlx-core 0.8.3 fs/ReadDir#inner.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::ReadDirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/ReadDir#>,
10 }
11
12 pub struct DirEntryrust-analyzer cargo sqlx-core 0.8.3 fs/DirEntry# {
13 pub pathrust-analyzer cargo sqlx-core 0.8.3 fs/DirEntry#path.: PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#,
14 pub file_namerust-analyzer cargo sqlx-core 0.8.3 fs/DirEntry#file_name.: OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#,
15 pub metadatarust-analyzer cargo sqlx-core 0.8.3 fs/DirEntry#metadata.: Metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/Metadata#,
16 }
17
18 // Filesystem operations are generally not capable of being non-blocking
19 // so Tokio and async-std don't bother; they just send the work to a blocking thread pool.
20 //
21 // We save on code duplication here by just implementing the same strategy ourselves
22 // using the runtime's `spawn_blocking()` primitive.
23
24 pub async fn readrust-analyzer cargo sqlx-core 0.8.3 fs/read().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(path: P) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> {
25 let path = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().(path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().());
26 rtrust-analyzer cargo sqlx-core 0.8.3 rt/::spawn_blockingrust-analyzer cargo sqlx-core 0.8.3 rt/spawn_blocking().(move || stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read().(path)).rust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().awaitrust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().
27 }
28
29 pub async fn read_to_stringrust-analyzer cargo sqlx-core 0.8.3 fs/read_to_string().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(path: P) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
30 let path = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().(path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().());
31 rtrust-analyzer cargo sqlx-core 0.8.3 rt/::spawn_blockingrust-analyzer cargo sqlx-core 0.8.3 rt/spawn_blocking().(move || stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(path)).rust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().awaitrust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().
32 }
33
34 pub async fn create_dir_allrust-analyzer cargo sqlx-core 0.8.3 fs/create_dir_all().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(path: P) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
35 let path = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().(path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().());
36 rtrust-analyzer cargo sqlx-core 0.8.3 rt/::spawn_blockingrust-analyzer cargo sqlx-core 0.8.3 rt/spawn_blocking().(move || stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::create_dir_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir_all().(path)).rust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().awaitrust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().
37 }
38
39 pub async fn remove_filerust-analyzer cargo sqlx-core 0.8.3 fs/remove_file().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(path: P) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
40 let path = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().(path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().());
41 rtrust-analyzer cargo sqlx-core 0.8.3 rt/::spawn_blockingrust-analyzer cargo sqlx-core 0.8.3 rt/spawn_blocking().(move || stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(path)).rust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().awaitrust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().
42 }
43
44 pub async fn remove_dirrust-analyzer cargo sqlx-core 0.8.3 fs/remove_dir().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(path: P) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
45 let path = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().(path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().());
46 rtrust-analyzer cargo sqlx-core 0.8.3 rt/::spawn_blockingrust-analyzer cargo sqlx-core 0.8.3 rt/spawn_blocking().(move || stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::remove_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_dir().(path)).rust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().awaitrust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().
47 }
48
49 pub async fn remove_dir_allrust-analyzer cargo sqlx-core 0.8.3 fs/remove_dir_all().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(path: P) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
50 let path = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().(path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().());
51 rtrust-analyzer cargo sqlx-core 0.8.3 rt/::spawn_blockingrust-analyzer cargo sqlx-core 0.8.3 rt/spawn_blocking().(move || stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::remove_dir_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_dir_all().(path)).rust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().awaitrust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().
52 }
53
54 pub async fn read_dirrust-analyzer cargo sqlx-core 0.8.3 fs/read_dir().(path: PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<ReadDirrust-analyzer cargo sqlx-core 0.8.3 fs/ReadDir#> {
55 let read_dir = rtrust-analyzer cargo sqlx-core 0.8.3 rt/::spawn_blockingrust-analyzer cargo sqlx-core 0.8.3 rt/spawn_blocking().(move || stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_dir().(path)).rust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().awaitrust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
56
57 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ReadDirrust-analyzer cargo sqlx-core 0.8.3 fs/ReadDir# {
58 innerrust-analyzer cargo sqlx-core 0.8.3 fs/ReadDir#inner.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(read_dir),
59 })
60 }
61
62 impl ReadDirrust-analyzer cargo sqlx-core 0.8.3 fs/ReadDir# {
63 pub async fn nextrust-analyzer cargo sqlx-core 0.8.3 fs/impl#[ReadDir]next().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<DirEntryrust-analyzer cargo sqlx-core 0.8.3 fs/DirEntry#>> {
64 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut read_dir) = self.innerrust-analyzer cargo sqlx-core 0.8.3 fs/ReadDir#inner..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() {
65 let maybe = rtrust-analyzer cargo sqlx-core 0.8.3 rt/::spawn_blockingrust-analyzer cargo sqlx-core 0.8.3 rt/spawn_blocking().(move || {
66 let entry = read_dir.nextrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[ReadDir][Iterator]next().().transposerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<Result<T, E>>`]transpose().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
67
68 entry
69 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|entry| -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<_> {
70 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((
71 read_dir,
72 DirEntryrust-analyzer cargo sqlx-core 0.8.3 fs/DirEntry# {
73 pathrust-analyzer cargo sqlx-core 0.8.3 fs/DirEntry#path.: entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().(),
74 file_namerust-analyzer cargo sqlx-core 0.8.3 fs/DirEntry#file_name.: entry.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]file_name().(),
75 // We always want the metadata as well so might as well fetch
76 // it in the same blocking call.
77 metadatarust-analyzer cargo sqlx-core 0.8.3 fs/DirEntry#metadata.: entry.metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]metadata().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
78 },
79 ))
80 })
81 .transposerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<Result<T, E>>`]transpose().()
82 })
83 .rust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().awaitrust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
84
85 match maybe {
86 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((read_dir, entry)) => {
87 self.innerrust-analyzer cargo sqlx-core 0.8.3 fs/ReadDir#inner. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(read_dir);
88 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(entry))
89 }
90 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
91 }
92 } else {
93 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)
94 }
95 }
96 }