browser_protocol/filesystem/
mod.rs1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3use std::borrow::Cow;
4
5
6#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7#[serde(rename_all = "camelCase")]
8pub struct File<'a> {
9 name: Cow<'a, str>,
10 #[serde(rename = "lastModified")]
12 last_modified: crate::network::TimeSinceEpoch,
13 size: f64,
15 #[serde(rename = "type")]
16 type_: Cow<'a, str>,
17}
18
19impl<'a> File<'a> {
20 pub fn builder(name: impl Into<Cow<'a, str>>, last_modified: crate::network::TimeSinceEpoch, size: f64, type_: impl Into<Cow<'a, str>>) -> FileBuilder<'a> {
26 FileBuilder {
27 name: name.into(),
28 last_modified: last_modified,
29 size: size,
30 type_: type_.into(),
31 }
32 }
33 pub fn name(&self) -> &str { self.name.as_ref() }
34 pub fn last_modified(&self) -> &crate::network::TimeSinceEpoch { &self.last_modified }
36 pub fn size(&self) -> f64 { self.size }
38 pub fn type_(&self) -> &str { self.type_.as_ref() }
39}
40
41
42pub struct FileBuilder<'a> {
43 name: Cow<'a, str>,
44 last_modified: crate::network::TimeSinceEpoch,
45 size: f64,
46 type_: Cow<'a, str>,
47}
48
49impl<'a> FileBuilder<'a> {
50 pub fn build(self) -> File<'a> {
51 File {
52 name: self.name,
53 last_modified: self.last_modified,
54 size: self.size,
55 type_: self.type_,
56 }
57 }
58}
59
60
61#[derive(Debug, Clone, Serialize, Deserialize, Default)]
62#[serde(rename_all = "camelCase")]
63pub struct Directory<'a> {
64 name: Cow<'a, str>,
65 #[serde(rename = "nestedDirectories")]
66 nested_directories: Vec<Cow<'a, str>>,
67 #[serde(rename = "nestedFiles")]
69 nested_files: Vec<File<'a>>,
70}
71
72impl<'a> Directory<'a> {
73 pub fn builder(name: impl Into<Cow<'a, str>>, nested_directories: Vec<Cow<'a, str>>, nested_files: Vec<File<'a>>) -> DirectoryBuilder<'a> {
78 DirectoryBuilder {
79 name: name.into(),
80 nested_directories: nested_directories,
81 nested_files: nested_files,
82 }
83 }
84 pub fn name(&self) -> &str { self.name.as_ref() }
85 pub fn nested_directories(&self) -> &[Cow<'a, str>] { &self.nested_directories }
86 pub fn nested_files(&self) -> &[File<'a>] { &self.nested_files }
88}
89
90
91pub struct DirectoryBuilder<'a> {
92 name: Cow<'a, str>,
93 nested_directories: Vec<Cow<'a, str>>,
94 nested_files: Vec<File<'a>>,
95}
96
97impl<'a> DirectoryBuilder<'a> {
98 pub fn build(self) -> Directory<'a> {
99 Directory {
100 name: self.name,
101 nested_directories: self.nested_directories,
102 nested_files: self.nested_files,
103 }
104 }
105}
106
107
108#[derive(Debug, Clone, Serialize, Deserialize, Default)]
109#[serde(rename_all = "camelCase")]
110pub struct BucketFileSystemLocator<'a> {
111 #[serde(rename = "storageKey")]
113 storage_key: crate::storage::SerializedStorageKey<'a>,
114 #[serde(skip_serializing_if = "Option::is_none", rename = "bucketName")]
116 bucket_name: Option<Cow<'a, str>>,
117 #[serde(rename = "pathComponents")]
119 path_components: Vec<Cow<'a, str>>,
120}
121
122impl<'a> BucketFileSystemLocator<'a> {
123 pub fn builder(storage_key: crate::storage::SerializedStorageKey<'a>, path_components: Vec<Cow<'a, str>>) -> BucketFileSystemLocatorBuilder<'a> {
127 BucketFileSystemLocatorBuilder {
128 storage_key: storage_key,
129 bucket_name: None,
130 path_components: path_components,
131 }
132 }
133 pub fn storage_key(&self) -> &crate::storage::SerializedStorageKey<'a> { &self.storage_key }
135 pub fn bucket_name(&self) -> Option<&str> { self.bucket_name.as_deref() }
137 pub fn path_components(&self) -> &[Cow<'a, str>] { &self.path_components }
139}
140
141
142pub struct BucketFileSystemLocatorBuilder<'a> {
143 storage_key: crate::storage::SerializedStorageKey<'a>,
144 bucket_name: Option<Cow<'a, str>>,
145 path_components: Vec<Cow<'a, str>>,
146}
147
148impl<'a> BucketFileSystemLocatorBuilder<'a> {
149 pub fn bucket_name(mut self, bucket_name: impl Into<Cow<'a, str>>) -> Self { self.bucket_name = Some(bucket_name.into()); self }
151 pub fn build(self) -> BucketFileSystemLocator<'a> {
152 BucketFileSystemLocator {
153 storage_key: self.storage_key,
154 bucket_name: self.bucket_name,
155 path_components: self.path_components,
156 }
157 }
158}
159
160
161#[derive(Debug, Clone, Serialize, Deserialize, Default)]
162#[serde(rename_all = "camelCase")]
163pub struct GetDirectoryParams<'a> {
164 #[serde(rename = "bucketFileSystemLocator")]
165 bucket_file_system_locator: BucketFileSystemLocator<'a>,
166}
167
168impl<'a> GetDirectoryParams<'a> {
169 pub fn builder(bucket_file_system_locator: BucketFileSystemLocator<'a>) -> GetDirectoryParamsBuilder<'a> {
172 GetDirectoryParamsBuilder {
173 bucket_file_system_locator: bucket_file_system_locator,
174 }
175 }
176 pub fn bucket_file_system_locator(&self) -> &BucketFileSystemLocator<'a> { &self.bucket_file_system_locator }
177}
178
179
180pub struct GetDirectoryParamsBuilder<'a> {
181 bucket_file_system_locator: BucketFileSystemLocator<'a>,
182}
183
184impl<'a> GetDirectoryParamsBuilder<'a> {
185 pub fn build(self) -> GetDirectoryParams<'a> {
186 GetDirectoryParams {
187 bucket_file_system_locator: self.bucket_file_system_locator,
188 }
189 }
190}
191
192
193#[derive(Debug, Clone, Serialize, Deserialize, Default)]
194#[serde(rename_all = "camelCase")]
195pub struct GetDirectoryReturns<'a> {
196 directory: Directory<'a>,
198}
199
200impl<'a> GetDirectoryReturns<'a> {
201 pub fn builder(directory: Directory<'a>) -> GetDirectoryReturnsBuilder<'a> {
204 GetDirectoryReturnsBuilder {
205 directory: directory,
206 }
207 }
208 pub fn directory(&self) -> &Directory<'a> { &self.directory }
210}
211
212
213pub struct GetDirectoryReturnsBuilder<'a> {
214 directory: Directory<'a>,
215}
216
217impl<'a> GetDirectoryReturnsBuilder<'a> {
218 pub fn build(self) -> GetDirectoryReturns<'a> {
219 GetDirectoryReturns {
220 directory: self.directory,
221 }
222 }
223}
224
225impl<'a> GetDirectoryParams<'a> { pub const METHOD: &'static str = "FileSystem.getDirectory"; }
226
227impl<'a> crate::CdpCommand<'a> for GetDirectoryParams<'a> {
228 const METHOD: &'static str = "FileSystem.getDirectory";
229 type Response = GetDirectoryReturns<'a>;
230}