ferroui_base/platform/storage/i_storage_item.rs
1use super::{IStorageFile, IStorageFolder, IStorageItemWithFileSystemInfo, StorageItemProperties};
2use crate::input::LocalBoxFuture;
3use crate::reactive::IDisposable;
4use crate::utilities::Uri;
5use std::any::Any;
6use std::rc::Rc;
7
8/// Manipulates storage items (files and folders) and their contents, and
9/// provides information about them.
10///
11/// This interface inherits [`IDisposable`]. It is recommended to dispose an
12/// item when it is not used anymore.
13///
14/// This interface is not meant to be implemented by applications.
15pub trait IStorageItem: IDisposable {
16 /// The name of the item including the file name extension if there is
17 /// one.
18 fn name(&self) -> String;
19
20 /// The file-system path of the item.
21 ///
22 /// Android backend might return a file path with "content:" scheme.
23 /// Browser and iOS backends might return a relative URI.
24 fn path(&self) -> Uri;
25
26 /// Gets the basic properties of the current item.
27 fn get_basic_properties_async(&self) -> LocalBoxFuture<StorageItemProperties>;
28
29 /// Returns `true` if it is possible to bookmark this file or folder for
30 /// future access.
31 fn can_bookmark(&self) -> bool;
32
33 /// Saves a bookmark for this file or folder.
34 ///
35 /// Resolves to an identifier of the bookmark, or `None` if a bookmark
36 /// cannot be created.
37 fn save_bookmark_async(&self) -> LocalBoxFuture<Option<String>>;
38
39 /// Gets the parent folder of the current storage item.
40 fn get_parent_async(&self) -> LocalBoxFuture<Option<Rc<dyn IStorageFolder>>>;
41
42 /// Deletes the current storage item and its contents.
43 fn delete_async(&self) -> LocalBoxFuture<std::io::Result<()>>;
44
45 /// Moves the current storage item and its contents to an
46 /// [`IStorageFolder`].
47 ///
48 /// Resolves to the storage item at its new location, if the platform
49 /// can provide it.
50 fn move_async(
51 &self,
52 destination: Rc<dyn IStorageFolder>,
53 ) -> LocalBoxFuture<std::io::Result<Option<Rc<dyn IStorageItem>>>>;
54
55 /// The item as a file, if it is one (C# `item as IStorageFile`).
56 fn as_storage_file(self: Rc<Self>) -> Option<Rc<dyn IStorageFile>> {
57 None
58 }
59
60 /// The item as a folder, if it is one (C# `item as IStorageFolder`).
61 fn as_storage_folder(self: Rc<Self>) -> Option<Rc<dyn IStorageFolder>> {
62 None
63 }
64
65 /// The item as one that is backed by an entry of the local file
66 /// system, if it is one.
67 fn as_storage_item_with_file_system_info(&self) -> Option<&dyn IStorageItemWithFileSystemInfo> {
68 None
69 }
70
71 /// The item as its concrete type, for a storage provider that
72 /// recognises its own items (C# `item as JSStorageItem`). `None` unless
73 /// the implementation opts in.
74 fn as_any(&self) -> Option<&dyn Any> {
75 None
76 }
77}