@@ -43,10 +43,20 @@ use crate::{Error, ErrorKind, Result};
43
43
/// | GCS | `storage-gcs` | `gcs` |
44
44
#[ derive( Clone , Debug ) ]
45
45
pub struct FileIO {
46
+ builder : FileIOBuilder ,
47
+
46
48
inner : Arc < Storage > ,
47
49
}
48
50
49
51
impl FileIO {
52
+ /// Convert FileIO into [`FileIOBuilder`] which used to build this FileIO.
53
+ ///
54
+ /// This function is useful when you want serialize and deserialize FileIO across
55
+ /// distributed systems.
56
+ pub fn into_builder ( self ) -> FileIOBuilder {
57
+ self . builder
58
+ }
59
+
50
60
/// Try to infer file io scheme from path. See [`FileIO`] for supported schemes.
51
61
///
52
62
/// - If it's a valid url, for example `s3://bucket/a`, url scheme will be used, and the rest of the url will be ignored.
@@ -134,7 +144,7 @@ impl FileIO {
134
144
}
135
145
136
146
/// Builder for [`FileIO`].
137
- #[ derive( Debug ) ]
147
+ #[ derive( Clone , Debug ) ]
138
148
pub struct FileIOBuilder {
139
149
/// This is used to infer scheme of operator.
140
150
///
@@ -165,7 +175,7 @@ impl FileIOBuilder {
165
175
/// Fetch the scheme string.
166
176
///
167
177
/// The scheme_str will be empty if it's None.
168
- pub ( crate ) fn into_parts ( self ) -> ( String , HashMap < String , String > ) {
178
+ pub fn into_parts ( self ) -> ( String , HashMap < String , String > ) {
169
179
( self . scheme_str . unwrap_or_default ( ) , self . props )
170
180
}
171
181
@@ -186,9 +196,10 @@ impl FileIOBuilder {
186
196
}
187
197
188
198
/// Builds [`FileIO`].
189
- pub fn build ( self ) -> crate :: Result < FileIO > {
190
- let storage = Storage :: build ( self ) ?;
199
+ pub fn build ( self ) -> Result < FileIO > {
200
+ let storage = Storage :: build ( self . clone ( ) ) ?;
191
201
Ok ( FileIO {
202
+ builder : self ,
192
203
inner : Arc :: new ( storage) ,
193
204
} )
194
205
}
0 commit comments