ferroui_base/platform/storage/
noop_storage_provider.rs1use super::{
2 FilePickerOpenOptions, FilePickerSaveOptions, FolderPickerOpenOptions, IStorageFolder, OpenFilePickerResult,
3 SaveFilePickerResult,
4};
5use crate::input::LocalBoxFuture;
6use std::rc::Rc;
7
8pub struct NoopStorageProvider;
13
14fn ready<T: 'static>(value: T) -> LocalBoxFuture<T> {
15 Box::pin(std::future::ready(value))
16}
17
18impl NoopStorageProvider {
19 fn open_file_picker_with_result() -> LocalBoxFuture<std::io::Result<OpenFilePickerResult>> {
20 ready(Ok(OpenFilePickerResult::default()))
21 }
22
23 fn save_file_picker_with_result() -> LocalBoxFuture<std::io::Result<SaveFilePickerResult>> {
24 ready(Ok(SaveFilePickerResult::default()))
25 }
26
27 fn open_folder_picker() -> LocalBoxFuture<std::io::Result<Vec<Rc<dyn IStorageFolder>>>> {
28 ready(Ok(Vec::new()))
29 }
30}
31
32#[cfg(not(target_arch = "wasm32"))]
33impl super::file_io::BclStorageProvider for NoopStorageProvider {
34 fn can_open(&self) -> bool {
35 false
36 }
37
38 fn open_file_picker_with_result_async(
39 &self,
40 _options: FilePickerOpenOptions,
41 ) -> LocalBoxFuture<std::io::Result<OpenFilePickerResult>> {
42 Self::open_file_picker_with_result()
43 }
44
45 fn can_save(&self) -> bool {
46 false
47 }
48
49 fn save_file_picker_with_result_async(
50 &self,
51 _options: FilePickerSaveOptions,
52 ) -> LocalBoxFuture<std::io::Result<SaveFilePickerResult>> {
53 Self::save_file_picker_with_result()
54 }
55
56 fn can_pick_folder(&self) -> bool {
57 false
58 }
59
60 fn open_folder_picker_async(
61 &self,
62 _options: FolderPickerOpenOptions,
63 ) -> LocalBoxFuture<std::io::Result<Vec<Rc<dyn IStorageFolder>>>> {
64 Self::open_folder_picker()
65 }
66}
67
68#[cfg(target_arch = "wasm32")]
70impl super::IStorageProvider for NoopStorageProvider {
71 fn can_open(&self) -> bool {
72 false
73 }
74
75 fn open_file_picker_async(
76 &self,
77 _options: FilePickerOpenOptions,
78 ) -> LocalBoxFuture<std::io::Result<Vec<Rc<dyn super::IStorageFile>>>> {
79 ready(Ok(Vec::new()))
80 }
81
82 fn open_file_picker_with_result_async(
83 &self,
84 _options: FilePickerOpenOptions,
85 ) -> LocalBoxFuture<std::io::Result<OpenFilePickerResult>> {
86 Self::open_file_picker_with_result()
87 }
88
89 fn can_save(&self) -> bool {
90 false
91 }
92
93 fn save_file_picker_async(
94 &self,
95 _options: FilePickerSaveOptions,
96 ) -> LocalBoxFuture<std::io::Result<Option<Rc<dyn super::IStorageFile>>>> {
97 ready(Ok(None))
98 }
99
100 fn save_file_picker_with_result_async(
101 &self,
102 _options: FilePickerSaveOptions,
103 ) -> LocalBoxFuture<std::io::Result<SaveFilePickerResult>> {
104 Self::save_file_picker_with_result()
105 }
106
107 fn can_pick_folder(&self) -> bool {
108 false
109 }
110
111 fn open_folder_picker_async(
112 &self,
113 _options: FolderPickerOpenOptions,
114 ) -> LocalBoxFuture<std::io::Result<Vec<Rc<dyn IStorageFolder>>>> {
115 Self::open_folder_picker()
116 }
117
118 fn open_file_bookmark_async(&self, _bookmark: &str) -> LocalBoxFuture<Option<Rc<dyn super::IStorageBookmarkFile>>> {
119 ready(None)
120 }
121
122 fn open_folder_bookmark_async(
123 &self,
124 _bookmark: &str,
125 ) -> LocalBoxFuture<Option<Rc<dyn super::IStorageBookmarkFolder>>> {
126 ready(None)
127 }
128
129 fn try_get_file_from_path_async(
130 &self,
131 _file_path: &crate::utilities::Uri,
132 ) -> LocalBoxFuture<Option<Rc<dyn super::IStorageFile>>> {
133 ready(None)
134 }
135
136 fn try_get_folder_from_path_async(
137 &self,
138 _folder_path: &crate::utilities::Uri,
139 ) -> LocalBoxFuture<Option<Rc<dyn IStorageFolder>>> {
140 ready(None)
141 }
142
143 fn try_get_well_known_folder_async(
144 &self,
145 _well_known_folder: super::WellKnownFolder,
146 ) -> LocalBoxFuture<Option<Rc<dyn IStorageFolder>>> {
147 ready(None)
148 }
149}