wasmer_bus_fuse/api/
mod.rs

1use serde::*;
2use std::io;
3use std::sync::Arc;
4#[allow(unused_imports)]
5use wasmer_bus::macros::*;
6
7/*
8#[wasmer_bus(format = "json")]
9pub trait Fuse {
10    async fn mount(&self, name: String) -> Arc<dyn FileSystem>;
11}
12
13#[wasmer_bus(format = "json")]
14pub trait FileSystem {
15    async fn init(&self) -> FsResult<()>;
16    async fn read_dir(&self, path: String) -> FsResult<Dir>;
17    async fn create_dir(&self, path: String) -> FsResult<Metadata>;
18    async fn remove_dir(&self, path: String) -> FsResult<()>;
19    async fn rename(&self, from: String, to: String) -> FsResult<()>;
20    async fn remove_file(&self, path: String) -> FsResult<()>;
21    async fn read_metadata(&self, path: String) -> FsResult<Metadata>;
22    async fn read_symlink_metadata(&self, path: String) -> FsResult<Metadata>;
23    async fn open(&self, path: String, options: OpenOptions) -> Arc<dyn OpenedFile>;
24}
25
26#[wasmer_bus(format = "json")]
27pub trait OpenedFile {
28    async fn meta(&self) -> FsResult<Metadata>;
29    async fn unlink(&self) -> FsResult<()>;
30    async fn set_len(&self, len: u64) -> FsResult<()>;
31    async fn io(&self) -> Arc<dyn FileIO>;
32}
33
34#[wasmer_bus(format = "bincode")]
35pub trait FileIO {
36    async fn seek(&self, from: SeekFrom) -> FsResult<u64>;
37    async fn flush(&self) -> FsResult<()>;
38    async fn write(&self, data: Vec<u8>) -> FsResult<u64>;
39    async fn read(&self, len: u64) -> FsResult<Vec<u8>>;
40}
41*/
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct OpenOptions {
45    pub read: bool,
46    pub write: bool,
47    pub create_new: bool,
48    pub create: bool,
49    pub append: bool,
50    pub truncate: bool,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub enum SeekFrom {
55    Start(u64),
56    End(i64),
57    Current(i64),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize, Default)]
61pub struct FileType {
62    pub dir: bool,
63    pub file: bool,
64    pub symlink: bool,
65    pub char_device: bool,
66    pub block_device: bool,
67    pub socket: bool,
68    pub fifo: bool,
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct Metadata {
73    pub ft: FileType,
74    pub accessed: u64,
75    pub created: u64,
76    pub modified: u64,
77    pub len: u64,
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct DirEntry {
82    pub path: String,
83    pub metadata: Option<Metadata>,
84}
85
86#[derive(Debug, Clone, Serialize, Deserialize, Default)]
87pub struct Dir {
88    pub data: Vec<DirEntry>,
89}
90
91#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
92pub enum FsError {
93    BaseNotDirectory,
94    NotAFile,
95    InvalidFd,
96    AlreadyExists,
97    Lock,
98    IOError,
99    AddressInUse,
100    AddressNotAvailable,
101    BrokenPipe,
102    ConnectionAborted,
103    ConnectionRefused,
104    ConnectionReset,
105    Interrupted,
106    InvalidData,
107    InvalidInput,
108    NotConnected,
109    EntityNotFound,
110    NoDevice,
111    PermissionDenied,
112    TimedOut,
113    UnexpectedEof,
114    WouldBlock,
115    WriteZero,
116    DirectoryNotEmpty,
117    UnknownError,
118}
119
120impl std::fmt::Display for FsError {
121    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
122        match self {
123            FsError::BaseNotDirectory => write!(f, "base is not a directory"),
124            FsError::NotAFile => write!(f, "not a file"),
125            FsError::InvalidFd => write!(f, "invalid file descriptor"),
126            FsError::AlreadyExists => write!(f, "alreadt existed"),
127            FsError::Lock => write!(f, "lock failed"),
128            FsError::IOError => write!(f, "fs io error"),
129            FsError::AddressInUse => write!(f, "address in use"),
130            FsError::AddressNotAvailable => write!(f, "address not available"),
131            FsError::BrokenPipe => write!(f, "pipe is broken"),
132            FsError::ConnectionAborted => write!(f, "connection aborted"),
133            FsError::ConnectionRefused => write!(f, "connection refused"),
134            FsError::ConnectionReset => write!(f, "connection reset"),
135            FsError::Interrupted => write!(f, "interrupted"),
136            FsError::InvalidData => write!(f, "invalid data"),
137            FsError::InvalidInput => write!(f, "invalid input"),
138            FsError::NotConnected => write!(f, "not connected"),
139            FsError::EntityNotFound => write!(f, "entity not found"),
140            FsError::NoDevice => write!(f, "no device"),
141            FsError::PermissionDenied => write!(f, "permission denied"),
142            FsError::TimedOut => write!(f, "timeout has elapsed"),
143            FsError::UnexpectedEof => write!(f, "unexpected eof of file"),
144            FsError::WouldBlock => write!(f, "call would block"),
145            FsError::WriteZero => write!(f, "write zero"),
146            FsError::DirectoryNotEmpty => write!(f, "directory is not empty"),
147            FsError::UnknownError => write!(f, "unknown error"),
148        }
149    }
150}
151
152impl From<io::Error> for FsError {
153    fn from(io_error: io::Error) -> Self {
154        match io_error.kind() {
155            io::ErrorKind::AddrInUse => FsError::AddressInUse,
156            io::ErrorKind::AddrNotAvailable => FsError::AddressNotAvailable,
157            io::ErrorKind::AlreadyExists => FsError::AlreadyExists,
158            io::ErrorKind::BrokenPipe => FsError::BrokenPipe,
159            io::ErrorKind::ConnectionAborted => FsError::ConnectionAborted,
160            io::ErrorKind::ConnectionRefused => FsError::ConnectionRefused,
161            io::ErrorKind::ConnectionReset => FsError::ConnectionReset,
162            io::ErrorKind::Interrupted => FsError::Interrupted,
163            io::ErrorKind::InvalidData => FsError::InvalidData,
164            io::ErrorKind::InvalidInput => FsError::InvalidInput,
165            io::ErrorKind::NotConnected => FsError::NotConnected,
166            io::ErrorKind::NotFound => FsError::EntityNotFound,
167            io::ErrorKind::PermissionDenied => FsError::PermissionDenied,
168            io::ErrorKind::TimedOut => FsError::TimedOut,
169            io::ErrorKind::UnexpectedEof => FsError::UnexpectedEof,
170            io::ErrorKind::WouldBlock => FsError::WouldBlock,
171            io::ErrorKind::WriteZero => FsError::WriteZero,
172            io::ErrorKind::Other => FsError::IOError,
173            _ => FsError::UnknownError,
174        }
175    }
176}
177
178impl Into<io::ErrorKind> for FsError {
179    fn into(self) -> io::ErrorKind {
180        match self {
181            FsError::AddressInUse => io::ErrorKind::AddrInUse,
182            FsError::AddressNotAvailable => io::ErrorKind::AddrNotAvailable,
183            FsError::AlreadyExists => io::ErrorKind::AlreadyExists,
184            FsError::BrokenPipe => io::ErrorKind::BrokenPipe,
185            FsError::ConnectionAborted => io::ErrorKind::ConnectionAborted,
186            FsError::ConnectionRefused => io::ErrorKind::ConnectionRefused,
187            FsError::ConnectionReset => io::ErrorKind::ConnectionReset,
188            FsError::Interrupted => io::ErrorKind::Interrupted,
189            FsError::InvalidData => io::ErrorKind::InvalidData,
190            FsError::InvalidInput => io::ErrorKind::InvalidInput,
191            FsError::NotConnected => io::ErrorKind::NotConnected,
192            FsError::EntityNotFound => io::ErrorKind::NotFound,
193            FsError::PermissionDenied => io::ErrorKind::PermissionDenied,
194            FsError::TimedOut => io::ErrorKind::TimedOut,
195            FsError::UnexpectedEof => io::ErrorKind::UnexpectedEof,
196            FsError::WouldBlock => io::ErrorKind::WouldBlock,
197            FsError::WriteZero => io::ErrorKind::WriteZero,
198            FsError::IOError => io::ErrorKind::Other,
199            _ => io::ErrorKind::Other,
200        }
201    }
202}
203
204impl Into<io::Error> for FsError {
205    fn into(self) -> io::Error {
206        let kind: io::ErrorKind = self.into();
207        kind.into()
208    }
209}
210
211impl Into<Box<dyn std::error::Error>> for FsError {
212    fn into(self) -> Box<dyn std::error::Error> {
213        let kind: io::ErrorKind = self.into();
214        let err: io::Error = kind.into();
215        Box::new(err)
216    }
217}
218
219pub type FsResult<T> = Result<T, FsError>;
220
221#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
222pub struct FuseMountRequest {
223    pub name: String,
224}
225#[wasmer_bus::async_trait]
226pub trait Fuse
227where
228    Self: std::fmt::Debug + Send + Sync,
229{
230    async fn mount(
231        &self,
232        name: String,
233    ) -> std::result::Result<std::sync::Arc<dyn FileSystem>, wasmer_bus::abi::BusError>;
234    fn blocking_mount(
235        &self,
236        name: String,
237    ) -> std::result::Result<std::sync::Arc<dyn FileSystem>, wasmer_bus::abi::BusError>;
238    fn as_client(&self) -> Option<FuseClient>;
239}
240#[wasmer_bus::async_trait]
241pub trait FuseSimplified
242where
243    Self: std::fmt::Debug + Send + Sync,
244{
245    async fn mount(
246        &self,
247        name: String,
248    ) -> std::result::Result<std::sync::Arc<dyn FileSystem>, wasmer_bus::abi::BusError>;
249}
250#[wasmer_bus::async_trait]
251impl<T> Fuse for T
252where
253    T: FuseSimplified,
254{
255    async fn mount(
256        &self,
257        name: String,
258    ) -> std::result::Result<std::sync::Arc<dyn FileSystem>, wasmer_bus::abi::BusError> {
259        FuseSimplified::mount(self, name).await
260    }
261    fn blocking_mount(
262        &self,
263        name: String,
264    ) -> std::result::Result<std::sync::Arc<dyn FileSystem>, wasmer_bus::abi::BusError> {
265        wasmer_bus::task::block_on(FuseSimplified::mount(self, name))
266    }
267    fn as_client(&self) -> Option<FuseClient> {
268        None
269    }
270}
271#[derive(Debug, Clone)]
272pub struct FuseService {}
273impl FuseService {
274    #[allow(dead_code)]
275    pub(crate) fn attach(
276        wasm_me: std::sync::Arc<dyn Fuse>,
277        call_handle: wasmer_bus::abi::CallHandle,
278    ) {
279        {
280            let wasm_me = wasm_me.clone();
281            let call_handle = call_handle.clone();
282            wasmer_bus::task::respond_to(
283                call_handle,
284                wasmer_bus::abi::SerializationFormat::Json,
285                #[allow(unused_variables)]
286                move |wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: FuseMountRequest| {
287                    let wasm_me = wasm_me.clone();
288                    let name = wasm_req.name;
289                    async move {
290                        match wasm_me.mount(name).await {
291                            Ok(svc) => {
292                                FileSystemService::attach(svc, wasm_handle);
293                                wasmer_bus::abi::RespondActionTyped::<()>::Detach
294                            },
295                            Err(err) => wasmer_bus::abi::RespondActionTyped::<()>::Fault(err)
296                        }
297                    }
298                },
299            );
300        }
301    }
302    pub fn listen(wasm_me: std::sync::Arc<dyn Fuse>) {
303        {
304            let wasm_me = wasm_me.clone();
305            wasmer_bus::task::listen(
306                wasmer_bus::abi::SerializationFormat::Json,
307                #[allow(unused_variables)]
308                move |wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: FuseMountRequest| {
309                    let wasm_me = wasm_me.clone();
310                    let name = wasm_req.name;
311                    async move {
312                        match wasm_me.mount(name).await {
313                            Ok(svc) => {
314                                FileSystemService::attach(svc, wasm_handle);
315                                wasmer_bus::abi::ListenActionTyped::<()>::Detach
316                            },
317                            Err(err) => wasmer_bus::abi::ListenActionTyped::<()>::Fault(err)
318                        }
319                    }
320                },
321            );
322        }
323    }
324    pub fn serve() {
325        wasmer_bus::task::serve();
326    }
327}
328#[derive(Debug, Clone)]
329pub struct FuseClient {
330    ctx: wasmer_bus::abi::CallContext,
331    task: Option<wasmer_bus::abi::Call>,
332    join: Option<wasmer_bus::abi::CallJoin<()>>,
333}
334impl FuseClient {
335    pub fn new(wapm: &str) -> Self {
336        Self {
337            ctx: wasmer_bus::abi::CallContext::NewBusCall {
338                wapm: wapm.to_string().into(),
339                instance: None,
340            },
341            task: None,
342            join: None,
343        }
344    }
345    pub fn new_with_instance(wapm: &str, instance: &str, access_token: &str) -> Self {
346        Self {
347            ctx: wasmer_bus::abi::CallContext::NewBusCall {
348                wapm: wapm.to_string().into(),
349                instance: Some(wasmer_bus::abi::CallInstance::new(instance, access_token)),
350            },
351            task: None,
352            join: None,
353        }
354    }
355    pub fn attach(handle: wasmer_bus::abi::CallHandle) -> Self {
356        let handle = wasmer_bus::abi::CallSmartHandle::new(handle);
357        Self {
358            ctx: wasmer_bus::abi::CallContext::OwnedSubCall { parent: handle },
359            task: None,
360            join: None,
361        }
362    }
363    pub fn wait(self) -> Result<(), wasmer_bus::abi::BusError> {
364        if let Some(join) = self.join {
365            join.wait()?;
366        }
367        if let Some(task) = self.task {
368            task.join()?.wait()?;
369        }
370        Ok(())
371    }
372    pub fn try_wait(&mut self) -> Result<Option<()>, wasmer_bus::abi::BusError> {
373        if let Some(task) = self.task.take() {
374            self.join.replace(task.join()?);
375        }
376        if let Some(join) = self.join.as_mut() {
377            join.try_wait()
378        } else {
379            Ok(None)
380        }
381    }
382    pub async fn mount(
383        &self,
384        name: String,
385    ) -> std::result::Result<std::sync::Arc<dyn FileSystem>, wasmer_bus::abi::BusError> {
386        let request = FuseMountRequest { name };
387        let handle = wasmer_bus::abi::call(
388            self.ctx.clone(),
389            wasmer_bus::abi::SerializationFormat::Json,
390            request,
391        )
392        .detach()?;
393        Ok(Arc::new(FileSystemClient::attach(handle)))
394    }
395    pub fn blocking_mount(
396        &self,
397        name: String,
398    ) -> std::result::Result<std::sync::Arc<dyn FileSystem>, wasmer_bus::abi::BusError> {
399        wasmer_bus::task::block_on(self.mount(name))
400    }
401}
402impl std::future::Future for FuseClient {
403    type Output = Result<(), wasmer_bus::abi::BusError>;
404    fn poll(
405        mut self: std::pin::Pin<&mut Self>,
406        cx: &mut std::task::Context<'_>,
407    ) -> std::task::Poll<Self::Output> {
408        if let Some(task) = self.task.take() {
409            self.join.replace(task.join()?);
410        }
411        if let Some(join) = self.join.as_mut() {
412            let join = std::pin::Pin::new(join);
413            return join.poll(cx);
414        } else {
415            std::task::Poll::Ready(Ok(()))
416        }
417    }
418}
419#[wasmer_bus::async_trait]
420impl Fuse for FuseClient {
421    async fn mount(
422        &self,
423        name: String,
424    ) -> std::result::Result<std::sync::Arc<dyn FileSystem>, wasmer_bus::abi::BusError> {
425        FuseClient::mount(self, name).await
426    }
427    fn blocking_mount(
428        &self,
429        name: String,
430    ) -> std::result::Result<std::sync::Arc<dyn FileSystem>, wasmer_bus::abi::BusError> {
431        FuseClient::blocking_mount(self, name)
432    }
433    fn as_client(&self) -> Option<FuseClient> {
434        Some(self.clone())
435    }
436}
437
438#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
439pub struct FileSystemInitRequest {}
440#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
441pub struct FileSystemReadDirRequest {
442    pub path: String,
443}
444#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
445pub struct FileSystemCreateDirRequest {
446    pub path: String,
447}
448#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
449pub struct FileSystemRemoveDirRequest {
450    pub path: String,
451}
452#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
453pub struct FileSystemRenameRequest {
454    pub from: String,
455    pub to: String,
456}
457#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
458pub struct FileSystemRemoveFileRequest {
459    pub path: String,
460}
461#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
462pub struct FileSystemReadMetadataRequest {
463    pub path: String,
464}
465#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
466pub struct FileSystemReadSymlinkMetadataRequest {
467    pub path: String,
468}
469#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
470pub struct FileSystemOpenRequest {
471    pub path: String,
472    pub options: OpenOptions,
473}
474#[wasmer_bus::async_trait]
475pub trait FileSystem
476where
477    Self: std::fmt::Debug + Send + Sync,
478{
479    async fn init(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError>;
480    async fn read_dir(
481        &self,
482        path: String,
483    ) -> std::result::Result<FsResult<Dir>, wasmer_bus::abi::BusError>;
484    async fn create_dir(
485        &self,
486        path: String,
487    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError>;
488    async fn remove_dir(
489        &self,
490        path: String,
491    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError>;
492    async fn rename(
493        &self,
494        from: String,
495        to: String,
496    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError>;
497    async fn remove_file(
498        &self,
499        path: String,
500    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError>;
501    async fn read_metadata(
502        &self,
503        path: String,
504    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError>;
505    async fn read_symlink_metadata(
506        &self,
507        path: String,
508    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError>;
509    async fn open(
510        &self,
511        path: String,
512        options: OpenOptions,
513    ) -> std::result::Result<std::sync::Arc<dyn OpenedFile>, wasmer_bus::abi::BusError>;
514    fn blocking_init(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError>;
515    fn blocking_read_dir(
516        &self,
517        path: String,
518    ) -> std::result::Result<FsResult<Dir>, wasmer_bus::abi::BusError>;
519    fn blocking_create_dir(
520        &self,
521        path: String,
522    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError>;
523    fn blocking_remove_dir(
524        &self,
525        path: String,
526    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError>;
527    fn blocking_rename(
528        &self,
529        from: String,
530        to: String,
531    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError>;
532    fn blocking_remove_file(
533        &self,
534        path: String,
535    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError>;
536    fn blocking_read_metadata(
537        &self,
538        path: String,
539    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError>;
540    fn blocking_read_symlink_metadata(
541        &self,
542        path: String,
543    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError>;
544    fn blocking_open(
545        &self,
546        path: String,
547        options: OpenOptions,
548    ) -> std::result::Result<std::sync::Arc<dyn OpenedFile>, wasmer_bus::abi::BusError>;
549    fn as_client(&self) -> Option<FileSystemClient>;
550}
551#[wasmer_bus::async_trait]
552pub trait FileSystemSimplified
553where
554    Self: std::fmt::Debug + Send + Sync,
555{
556    async fn init(&self) -> FsResult<()>;
557    async fn read_dir(&self, path: String) -> FsResult<Dir>;
558    async fn create_dir(&self, path: String) -> FsResult<Metadata>;
559    async fn remove_dir(&self, path: String) -> FsResult<()>;
560    async fn rename(&self, from: String, to: String) -> FsResult<()>;
561    async fn remove_file(&self, path: String) -> FsResult<()>;
562    async fn read_metadata(&self, path: String) -> FsResult<Metadata>;
563    async fn read_symlink_metadata(&self, path: String) -> FsResult<Metadata>;
564    async fn open(
565        &self,
566        path: String,
567        options: OpenOptions,
568    ) -> std::result::Result<std::sync::Arc<dyn OpenedFile>, wasmer_bus::abi::BusError>;
569}
570#[wasmer_bus::async_trait]
571impl<T> FileSystem for T
572where
573    T: FileSystemSimplified,
574{
575    async fn init(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
576        Ok(FileSystemSimplified::init(self).await)
577    }
578    fn blocking_init(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
579        Ok(wasmer_bus::task::block_on(FileSystemSimplified::init(self)))
580    }
581    async fn read_dir(
582        &self,
583        path: String,
584    ) -> std::result::Result<FsResult<Dir>, wasmer_bus::abi::BusError> {
585        Ok(FileSystemSimplified::read_dir(self, path).await)
586    }
587    fn blocking_read_dir(
588        &self,
589        path: String,
590    ) -> std::result::Result<FsResult<Dir>, wasmer_bus::abi::BusError> {
591        Ok(wasmer_bus::task::block_on(FileSystemSimplified::read_dir(
592            self, path,
593        )))
594    }
595    async fn create_dir(
596        &self,
597        path: String,
598    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
599        Ok(FileSystemSimplified::create_dir(self, path).await)
600    }
601    fn blocking_create_dir(
602        &self,
603        path: String,
604    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
605        Ok(wasmer_bus::task::block_on(FileSystemSimplified::create_dir(
606            self, path,
607        )))
608    }
609    async fn remove_dir(
610        &self,
611        path: String,
612    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
613        Ok(FileSystemSimplified::remove_dir(self, path).await)
614    }
615    fn blocking_remove_dir(
616        &self,
617        path: String,
618    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
619        Ok(wasmer_bus::task::block_on(FileSystemSimplified::remove_dir(
620            self, path,
621        )))
622    }
623    async fn rename(
624        &self,
625        from: String,
626        to: String,
627    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
628        Ok(FileSystemSimplified::rename(self, from, to).await)
629    }
630    fn blocking_rename(
631        &self,
632        from: String,
633        to: String,
634    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
635        Ok(wasmer_bus::task::block_on(FileSystemSimplified::rename(
636            self, from, to,
637        )))
638    }
639    async fn remove_file(
640        &self,
641        path: String,
642    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
643        Ok(FileSystemSimplified::remove_file(self, path).await)
644    }
645    fn blocking_remove_file(
646        &self,
647        path: String,
648    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
649        Ok(wasmer_bus::task::block_on(FileSystemSimplified::remove_file(
650            self, path,
651        )))
652    }
653    async fn read_metadata(
654        &self,
655        path: String,
656    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
657        Ok(FileSystemSimplified::read_metadata(self, path).await)
658    }
659    fn blocking_read_metadata(
660        &self,
661        path: String,
662    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
663        Ok(wasmer_bus::task::block_on(
664            FileSystemSimplified::read_metadata(self, path),
665        ))
666    }
667    async fn read_symlink_metadata(
668        &self,
669        path: String,
670    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
671        Ok(FileSystemSimplified::read_symlink_metadata(self, path).await)
672    }
673    fn blocking_read_symlink_metadata(
674        &self,
675        path: String,
676    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
677        Ok(wasmer_bus::task::block_on(
678            FileSystemSimplified::read_symlink_metadata(self, path),
679        ))
680    }
681    async fn open(
682        &self,
683        path: String,
684        options: OpenOptions,
685    ) -> std::result::Result<std::sync::Arc<dyn OpenedFile>, wasmer_bus::abi::BusError> {
686        FileSystemSimplified::open(self, path, options).await
687    }
688    fn blocking_open(
689        &self,
690        path: String,
691        options: OpenOptions,
692    ) -> std::result::Result<std::sync::Arc<dyn OpenedFile>, wasmer_bus::abi::BusError> {
693        wasmer_bus::task::block_on(FileSystemSimplified::open(self, path, options))
694    }
695    fn as_client(&self) -> Option<FileSystemClient> {
696        None
697    }
698}
699#[derive(Debug, Clone)]
700pub struct FileSystemService {}
701impl FileSystemService {
702    #[allow(dead_code)]
703    pub(crate) fn attach(
704        wasm_me: std::sync::Arc<dyn FileSystem>,
705        call_handle: wasmer_bus::abi::CallHandle,
706    ) {
707        {
708            let wasm_me = wasm_me.clone();
709            let call_handle = call_handle.clone();
710            wasmer_bus::task::respond_to(
711                call_handle,
712                wasmer_bus::abi::SerializationFormat::Json,
713                #[allow(unused_variables)]
714                move |wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: FileSystemInitRequest| {
715                    let wasm_me = wasm_me.clone();
716                    async move {
717                        match wasm_me.init().await {
718                            Ok(res) => wasmer_bus::abi::RespondActionTyped::Response(res),
719                            Err(err) => wasmer_bus::abi::RespondActionTyped::Fault(err)
720                        }
721                    }
722                },
723            );
724        }
725        {
726            let wasm_me = wasm_me.clone();
727            let call_handle = call_handle.clone();
728            wasmer_bus::task::respond_to(
729                call_handle,
730                wasmer_bus::abi::SerializationFormat::Json,
731                #[allow(unused_variables)]
732                move |wasm_handle: wasmer_bus::abi::CallHandle,
733                      wasm_req: FileSystemReadDirRequest| {
734                    let wasm_me = wasm_me.clone();
735                    let path = wasm_req.path;
736                    async move {
737                        match wasm_me.read_dir(path).await {
738                            Ok(res) => wasmer_bus::abi::RespondActionTyped::Response(res),
739                            Err(err) => wasmer_bus::abi::RespondActionTyped::Fault(err)
740                        }
741                    }
742                },
743            );
744        }
745        {
746            let wasm_me = wasm_me.clone();
747            let call_handle = call_handle.clone();
748            wasmer_bus::task::respond_to(
749                call_handle,
750                wasmer_bus::abi::SerializationFormat::Json,
751                #[allow(unused_variables)]
752                move |wasm_handle: wasmer_bus::abi::CallHandle,
753                      wasm_req: FileSystemCreateDirRequest| {
754                    let wasm_me = wasm_me.clone();
755                    let path = wasm_req.path;
756                    async move {
757                        match wasm_me.create_dir(path).await {
758                            Ok(res) => wasmer_bus::abi::RespondActionTyped::Response(res),
759                            Err(err) => wasmer_bus::abi::RespondActionTyped::Fault(err)
760                        }
761                    }
762                },
763            );
764        }
765        {
766            let wasm_me = wasm_me.clone();
767            let call_handle = call_handle.clone();
768            wasmer_bus::task::respond_to(
769                call_handle,
770                wasmer_bus::abi::SerializationFormat::Json,
771                #[allow(unused_variables)]
772                move |wasm_handle: wasmer_bus::abi::CallHandle,
773                      wasm_req: FileSystemRemoveDirRequest| {
774                    let wasm_me = wasm_me.clone();
775                    let path = wasm_req.path;
776                    async move {
777                        match wasm_me.remove_dir(path).await {
778                            Ok(res) => wasmer_bus::abi::RespondActionTyped::Response(res),
779                            Err(err) => wasmer_bus::abi::RespondActionTyped::Fault(err)
780                        }
781                    }
782                },
783            );
784        }
785        {
786            let wasm_me = wasm_me.clone();
787            let call_handle = call_handle.clone();
788            wasmer_bus::task::respond_to(
789                call_handle,
790                wasmer_bus::abi::SerializationFormat::Json,
791                #[allow(unused_variables)]
792                move |wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: FileSystemRenameRequest| {
793                    let wasm_me = wasm_me.clone();
794                    let from = wasm_req.from;
795                    let to = wasm_req.to;
796                    async move {
797                        match wasm_me.rename(from, to).await {
798                            Ok(res) => wasmer_bus::abi::RespondActionTyped::Response(res),
799                            Err(err) => wasmer_bus::abi::RespondActionTyped::Fault(err)
800                        }
801                    }
802                },
803            );
804        }
805        {
806            let wasm_me = wasm_me.clone();
807            let call_handle = call_handle.clone();
808            wasmer_bus::task::respond_to(
809                call_handle,
810                wasmer_bus::abi::SerializationFormat::Json,
811                #[allow(unused_variables)]
812                move |wasm_handle: wasmer_bus::abi::CallHandle,
813                      wasm_req: FileSystemRemoveFileRequest| {
814                    let wasm_me = wasm_me.clone();
815                    let path = wasm_req.path;
816                    async move {
817                        match wasm_me.remove_file(path).await {
818                            Ok(res) => wasmer_bus::abi::RespondActionTyped::Response(res),
819                            Err(err) => wasmer_bus::abi::RespondActionTyped::Fault(err)
820                        }
821                    }
822                },
823            );
824        }
825        {
826            let wasm_me = wasm_me.clone();
827            let call_handle = call_handle.clone();
828            wasmer_bus::task::respond_to(
829                call_handle,
830                wasmer_bus::abi::SerializationFormat::Json,
831                #[allow(unused_variables)]
832                move |wasm_handle: wasmer_bus::abi::CallHandle,
833                      wasm_req: FileSystemReadMetadataRequest| {
834                    let wasm_me = wasm_me.clone();
835                    let path = wasm_req.path;
836                    async move {
837                        match wasm_me.read_metadata(path).await {
838                            Ok(res) => wasmer_bus::abi::RespondActionTyped::Response(res),
839                            Err(err) => wasmer_bus::abi::RespondActionTyped::Fault(err)
840                        }
841                    }
842                },
843            );
844        }
845        {
846            let wasm_me = wasm_me.clone();
847            let call_handle = call_handle.clone();
848            wasmer_bus::task::respond_to(
849                call_handle,
850                wasmer_bus::abi::SerializationFormat::Json,
851                #[allow(unused_variables)]
852                move |wasm_handle: wasmer_bus::abi::CallHandle,
853                      wasm_req: FileSystemReadSymlinkMetadataRequest| {
854                    let wasm_me = wasm_me.clone();
855                    let path = wasm_req.path;
856                    async move {
857                        match wasm_me.read_symlink_metadata(path).await {
858                            Ok(res) => wasmer_bus::abi::RespondActionTyped::Response(res),
859                            Err(err) => wasmer_bus::abi::RespondActionTyped::Fault(err)
860                        }
861                    }
862                },
863            );
864        }
865        {
866            let wasm_me = wasm_me.clone();
867            let call_handle = call_handle.clone();
868            wasmer_bus::task::respond_to(
869                call_handle,
870                wasmer_bus::abi::SerializationFormat::Json,
871                #[allow(unused_variables)]
872                move |wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: FileSystemOpenRequest| {
873                    let wasm_me = wasm_me.clone();
874                    let path = wasm_req.path;
875                    let options = wasm_req.options;
876                    async move {
877                        match wasm_me.open(path, options).await {
878                            Ok(svc) => {
879                                OpenedFileService::attach(svc, wasm_handle);
880                                wasmer_bus::abi::RespondActionTyped::<()>::Detach
881                            },
882                            Err(err) => wasmer_bus::abi::RespondActionTyped::<()>::Fault(err)
883                        }
884                    }
885                },
886            );
887        }
888    }
889    pub fn listen(wasm_me: std::sync::Arc<dyn FileSystem>) {
890        {
891            let wasm_me = wasm_me.clone();
892            wasmer_bus::task::listen(
893                wasmer_bus::abi::SerializationFormat::Json,
894                #[allow(unused_variables)]
895                move |_wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: FileSystemInitRequest| {
896                    let wasm_me = wasm_me.clone();
897                    async move {
898                        match wasm_me.init().await {
899                            Ok(res) => wasmer_bus::abi::ListenActionTyped::Response(res),
900                            Err(err) => wasmer_bus::abi::ListenActionTyped::Fault(err)
901                        }
902                    }
903                },
904            );
905        }
906        {
907            let wasm_me = wasm_me.clone();
908            wasmer_bus::task::listen(
909                wasmer_bus::abi::SerializationFormat::Json,
910                #[allow(unused_variables)]
911                move |_wasm_handle: wasmer_bus::abi::CallHandle,
912                      wasm_req: FileSystemReadDirRequest| {
913                    let wasm_me = wasm_me.clone();
914                    let path = wasm_req.path;
915                    async move {
916                        match wasm_me.read_dir(path).await {
917                            Ok(res) => wasmer_bus::abi::ListenActionTyped::Response(res),
918                            Err(err) => wasmer_bus::abi::ListenActionTyped::Fault(err)
919                        }
920                    }
921                },
922            );
923        }
924        {
925            let wasm_me = wasm_me.clone();
926            wasmer_bus::task::listen(
927                wasmer_bus::abi::SerializationFormat::Json,
928                #[allow(unused_variables)]
929                move |_wasm_handle: wasmer_bus::abi::CallHandle,
930                      wasm_req: FileSystemCreateDirRequest| {
931                    let wasm_me = wasm_me.clone();
932                    let path = wasm_req.path;
933                    async move {
934                        match wasm_me.create_dir(path).await {
935                            Ok(res) => wasmer_bus::abi::ListenActionTyped::Response(res),
936                            Err(err) => wasmer_bus::abi::ListenActionTyped::Fault(err)
937                        }
938                    }
939                },
940            );
941        }
942        {
943            let wasm_me = wasm_me.clone();
944            wasmer_bus::task::listen(
945                wasmer_bus::abi::SerializationFormat::Json,
946                #[allow(unused_variables)]
947                move |_wasm_handle: wasmer_bus::abi::CallHandle,
948                      wasm_req: FileSystemRemoveDirRequest| {
949                    let wasm_me = wasm_me.clone();
950                    let path = wasm_req.path;
951                    async move {
952                        match wasm_me.remove_dir(path).await {
953                            Ok(res) => wasmer_bus::abi::ListenActionTyped::Response(res),
954                            Err(err) => wasmer_bus::abi::ListenActionTyped::Fault(err)
955                        }
956                    }
957                },
958            );
959        }
960        {
961            let wasm_me = wasm_me.clone();
962            wasmer_bus::task::listen(
963                wasmer_bus::abi::SerializationFormat::Json,
964                #[allow(unused_variables)]
965                move |_wasm_handle: wasmer_bus::abi::CallHandle,
966                      wasm_req: FileSystemRenameRequest| {
967                    let wasm_me = wasm_me.clone();
968                    let from = wasm_req.from;
969                    let to = wasm_req.to;
970                    async move {
971                        match wasm_me.rename(from, to).await {
972                            Ok(res) => wasmer_bus::abi::ListenActionTyped::Response(res),
973                            Err(err) => wasmer_bus::abi::ListenActionTyped::Fault(err)
974                        }
975                    }
976                },
977            );
978        }
979        {
980            let wasm_me = wasm_me.clone();
981            wasmer_bus::task::listen(
982                wasmer_bus::abi::SerializationFormat::Json,
983                #[allow(unused_variables)]
984                move |_wasm_handle: wasmer_bus::abi::CallHandle,
985                      wasm_req: FileSystemRemoveFileRequest| {
986                    let wasm_me = wasm_me.clone();
987                    let path = wasm_req.path;
988                    async move {
989                        match wasm_me.remove_file(path).await {
990                            Ok(res) => wasmer_bus::abi::ListenActionTyped::Response(res),
991                            Err(err) => wasmer_bus::abi::ListenActionTyped::Fault(err)
992                        }
993                    }
994                },
995            );
996        }
997        {
998            let wasm_me = wasm_me.clone();
999            wasmer_bus::task::listen(
1000                wasmer_bus::abi::SerializationFormat::Json,
1001                #[allow(unused_variables)]
1002                move |_wasm_handle: wasmer_bus::abi::CallHandle,
1003                      wasm_req: FileSystemReadMetadataRequest| {
1004                    let wasm_me = wasm_me.clone();
1005                    let path = wasm_req.path;
1006                    async move {
1007                        match wasm_me.read_metadata(path).await {
1008                            Ok(res) => wasmer_bus::abi::ListenActionTyped::Response(res),
1009                            Err(err) => wasmer_bus::abi::ListenActionTyped::Fault(err)
1010                        }
1011                    }
1012                },
1013            );
1014        }
1015        {
1016            let wasm_me = wasm_me.clone();
1017            wasmer_bus::task::listen(
1018                wasmer_bus::abi::SerializationFormat::Json,
1019                #[allow(unused_variables)]
1020                move |_wasm_handle: wasmer_bus::abi::CallHandle,
1021                      wasm_req: FileSystemReadSymlinkMetadataRequest| {
1022                    let wasm_me = wasm_me.clone();
1023                    let path = wasm_req.path;
1024                    async move {
1025                        match wasm_me.read_symlink_metadata(path).await {
1026                            Ok(res) => wasmer_bus::abi::ListenActionTyped::Response(res),
1027                            Err(err) => wasmer_bus::abi::ListenActionTyped::Fault(err)
1028                        }
1029                    }
1030                },
1031            );
1032        }
1033        {
1034            let wasm_me = wasm_me.clone();
1035            wasmer_bus::task::listen(
1036                wasmer_bus::abi::SerializationFormat::Json,
1037                #[allow(unused_variables)]
1038                move |wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: FileSystemOpenRequest| {
1039                    let wasm_me = wasm_me.clone();
1040                    let path = wasm_req.path;
1041                    let options = wasm_req.options;
1042                    async move {
1043                        match wasm_me.open(path, options).await {
1044                            Ok(svc) => {
1045                                OpenedFileService::attach(svc, wasm_handle);
1046                                wasmer_bus::abi::ListenActionTyped::<()>::Detach
1047                            },
1048                            Err(err) => wasmer_bus::abi::ListenActionTyped::<()>::Fault(err)
1049                        }
1050                    }
1051                },
1052            );
1053        }
1054    }
1055    pub fn serve() {
1056        wasmer_bus::task::serve();
1057    }
1058}
1059#[derive(Debug, Clone)]
1060pub struct FileSystemClient {
1061    ctx: wasmer_bus::abi::CallContext,
1062    task: Option<wasmer_bus::abi::Call>,
1063    join: Option<wasmer_bus::abi::CallJoin<()>>,
1064}
1065impl FileSystemClient {
1066    pub fn new(wapm: &str) -> Self {
1067        Self {
1068            ctx: wasmer_bus::abi::CallContext::NewBusCall {
1069                wapm: wapm.to_string().into(),
1070                instance: None,
1071            },
1072            task: None,
1073            join: None,
1074        }
1075    }
1076    pub fn new_with_instance(wapm: &str, instance: &str, access_token: &str) -> Self {
1077        Self {
1078            ctx: wasmer_bus::abi::CallContext::NewBusCall {
1079                wapm: wapm.to_string().into(),
1080                instance: Some(wasmer_bus::abi::CallInstance::new(instance, access_token)),
1081            },
1082            task: None,
1083            join: None,
1084        }
1085    }
1086    pub fn attach(handle: wasmer_bus::abi::CallHandle) -> Self {
1087        let handle = wasmer_bus::abi::CallSmartHandle::new(handle);
1088        Self {
1089            ctx: wasmer_bus::abi::CallContext::OwnedSubCall { parent: handle },
1090            task: None,
1091            join: None,
1092        }
1093    }
1094    pub fn wait(self) -> Result<(), wasmer_bus::abi::BusError> {
1095        if let Some(join) = self.join {
1096            join.wait()?;
1097        }
1098        if let Some(task) = self.task {
1099            task.join()?.wait()?;
1100        }
1101        Ok(())
1102    }
1103    pub fn try_wait(&mut self) -> Result<Option<()>, wasmer_bus::abi::BusError> {
1104        if let Some(task) = self.task.take() {
1105            self.join.replace(task.join()?);
1106        }
1107        if let Some(join) = self.join.as_mut() {
1108            join.try_wait()
1109        } else {
1110            Ok(None)
1111        }
1112    }
1113    pub async fn init(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1114        let request = FileSystemInitRequest {};
1115        wasmer_bus::abi::call(
1116            self.ctx.clone(),
1117            wasmer_bus::abi::SerializationFormat::Json,
1118            request,
1119        )
1120        .invoke()
1121        .join()?
1122        .await
1123    }
1124    pub async fn read_dir(
1125        &self,
1126        path: String,
1127    ) -> std::result::Result<FsResult<Dir>, wasmer_bus::abi::BusError> {
1128        let request = FileSystemReadDirRequest { path };
1129        wasmer_bus::abi::call(
1130            self.ctx.clone(),
1131            wasmer_bus::abi::SerializationFormat::Json,
1132            request,
1133        )
1134        .invoke()
1135        .join()?
1136        .await
1137    }
1138    pub async fn create_dir(
1139        &self,
1140        path: String,
1141    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1142        let request = FileSystemCreateDirRequest { path };
1143        wasmer_bus::abi::call(
1144            self.ctx.clone(),
1145            wasmer_bus::abi::SerializationFormat::Json,
1146            request,
1147        )
1148        .invoke()
1149        .join()?
1150        .await
1151    }
1152    pub async fn remove_dir(
1153        &self,
1154        path: String,
1155    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1156        let request = FileSystemRemoveDirRequest { path };
1157        wasmer_bus::abi::call(
1158            self.ctx.clone(),
1159            wasmer_bus::abi::SerializationFormat::Json,
1160            request,
1161        )
1162        .invoke()
1163        .join()?
1164        .await
1165    }
1166    pub async fn rename(
1167        &self,
1168        from: String,
1169        to: String,
1170    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1171        let request = FileSystemRenameRequest { from, to };
1172        wasmer_bus::abi::call(
1173            self.ctx.clone(),
1174            wasmer_bus::abi::SerializationFormat::Json,
1175            request,
1176        )
1177        .invoke()
1178        .join()?
1179        .await
1180    }
1181    pub async fn remove_file(
1182        &self,
1183        path: String,
1184    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1185        let request = FileSystemRemoveFileRequest { path };
1186        wasmer_bus::abi::call(
1187            self.ctx.clone(),
1188            wasmer_bus::abi::SerializationFormat::Json,
1189            request,
1190        )
1191        .invoke()
1192        .join()?
1193        .await
1194    }
1195    pub async fn read_metadata(
1196        &self,
1197        path: String,
1198    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1199        let request = FileSystemReadMetadataRequest { path };
1200        wasmer_bus::abi::call(
1201            self.ctx.clone(),
1202            wasmer_bus::abi::SerializationFormat::Json,
1203            request,
1204        )
1205        .invoke()
1206        .join()?
1207        .await
1208    }
1209    pub async fn read_symlink_metadata(
1210        &self,
1211        path: String,
1212    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1213        let request = FileSystemReadSymlinkMetadataRequest { path };
1214        wasmer_bus::abi::call(
1215            self.ctx.clone(),
1216            wasmer_bus::abi::SerializationFormat::Json,
1217            request,
1218        )
1219        .invoke()
1220        .join()?
1221        .await
1222    }
1223    pub async fn open(
1224        &self,
1225        path: String,
1226        options: OpenOptions,
1227    ) -> std::result::Result<std::sync::Arc<dyn OpenedFile>, wasmer_bus::abi::BusError> {
1228        let request = FileSystemOpenRequest { path, options };
1229        let handle = wasmer_bus::abi::call(
1230            self.ctx.clone(),
1231            wasmer_bus::abi::SerializationFormat::Json,
1232            request,
1233        )
1234        .detach()?;
1235        Ok(Arc::new(OpenedFileClient::attach(handle)))
1236    }
1237    pub fn blocking_init(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1238        wasmer_bus::task::block_on(self.init())
1239    }
1240    pub fn blocking_read_dir(
1241        &self,
1242        path: String,
1243    ) -> std::result::Result<FsResult<Dir>, wasmer_bus::abi::BusError> {
1244        wasmer_bus::task::block_on(self.read_dir(path))
1245    }
1246    pub fn blocking_create_dir(
1247        &self,
1248        path: String,
1249    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1250        wasmer_bus::task::block_on(self.create_dir(path))
1251    }
1252    pub fn blocking_remove_dir(
1253        &self,
1254        path: String,
1255    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1256        wasmer_bus::task::block_on(self.remove_dir(path))
1257    }
1258    pub fn blocking_rename(
1259        &self,
1260        from: String,
1261        to: String,
1262    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1263        wasmer_bus::task::block_on(self.rename(from, to))
1264    }
1265    pub fn blocking_remove_file(
1266        &self,
1267        path: String,
1268    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1269        wasmer_bus::task::block_on(self.remove_file(path))
1270    }
1271    pub fn blocking_read_metadata(
1272        &self,
1273        path: String,
1274    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1275        wasmer_bus::task::block_on(self.read_metadata(path))
1276    }
1277    pub fn blocking_read_symlink_metadata(
1278        &self,
1279        path: String,
1280    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1281        wasmer_bus::task::block_on(self.read_symlink_metadata(path))
1282    }
1283    pub fn blocking_open(
1284        &self,
1285        path: String,
1286        options: OpenOptions,
1287    ) -> std::result::Result<std::sync::Arc<dyn OpenedFile>, wasmer_bus::abi::BusError> {
1288        wasmer_bus::task::block_on(self.open(path, options))
1289    }
1290}
1291impl std::future::Future for FileSystemClient {
1292    type Output = Result<(), wasmer_bus::abi::BusError>;
1293    fn poll(
1294        mut self: std::pin::Pin<&mut Self>,
1295        cx: &mut std::task::Context<'_>,
1296    ) -> std::task::Poll<Self::Output> {
1297        if let Some(task) = self.task.take() {
1298            self.join.replace(task.join()?);
1299        }
1300        if let Some(join) = self.join.as_mut() {
1301            let join = std::pin::Pin::new(join);
1302            return join.poll(cx);
1303        } else {
1304            std::task::Poll::Ready(Ok(()))
1305        }
1306    }
1307}
1308#[wasmer_bus::async_trait]
1309impl FileSystem for FileSystemClient {
1310    async fn init(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1311        FileSystemClient::init(self).await
1312    }
1313    fn blocking_init(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1314        FileSystemClient::blocking_init(self)
1315    }
1316    async fn read_dir(
1317        &self,
1318        path: String,
1319    ) -> std::result::Result<FsResult<Dir>, wasmer_bus::abi::BusError> {
1320        FileSystemClient::read_dir(self, path).await
1321    }
1322    fn blocking_read_dir(
1323        &self,
1324        path: String,
1325    ) -> std::result::Result<FsResult<Dir>, wasmer_bus::abi::BusError> {
1326        FileSystemClient::blocking_read_dir(self, path)
1327    }
1328    async fn create_dir(
1329        &self,
1330        path: String,
1331    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1332        FileSystemClient::create_dir(self, path).await
1333    }
1334    fn blocking_create_dir(
1335        &self,
1336        path: String,
1337    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1338        FileSystemClient::blocking_create_dir(self, path)
1339    }
1340    async fn remove_dir(
1341        &self,
1342        path: String,
1343    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1344        FileSystemClient::remove_dir(self, path).await
1345    }
1346    fn blocking_remove_dir(
1347        &self,
1348        path: String,
1349    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1350        FileSystemClient::blocking_remove_dir(self, path)
1351    }
1352    async fn rename(
1353        &self,
1354        from: String,
1355        to: String,
1356    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1357        FileSystemClient::rename(self, from, to).await
1358    }
1359    fn blocking_rename(
1360        &self,
1361        from: String,
1362        to: String,
1363    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1364        FileSystemClient::blocking_rename(self, from, to)
1365    }
1366    async fn remove_file(
1367        &self,
1368        path: String,
1369    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1370        FileSystemClient::remove_file(self, path).await
1371    }
1372    fn blocking_remove_file(
1373        &self,
1374        path: String,
1375    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1376        FileSystemClient::blocking_remove_file(self, path)
1377    }
1378    async fn read_metadata(
1379        &self,
1380        path: String,
1381    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1382        FileSystemClient::read_metadata(self, path).await
1383    }
1384    fn blocking_read_metadata(
1385        &self,
1386        path: String,
1387    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1388        FileSystemClient::blocking_read_metadata(self, path)
1389    }
1390    async fn read_symlink_metadata(
1391        &self,
1392        path: String,
1393    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1394        FileSystemClient::read_symlink_metadata(self, path).await
1395    }
1396    fn blocking_read_symlink_metadata(
1397        &self,
1398        path: String,
1399    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1400        FileSystemClient::blocking_read_symlink_metadata(self, path)
1401    }
1402    async fn open(
1403        &self,
1404        path: String,
1405        options: OpenOptions,
1406    ) -> std::result::Result<std::sync::Arc<dyn OpenedFile>, wasmer_bus::abi::BusError> {
1407        FileSystemClient::open(self, path, options).await
1408    }
1409    fn blocking_open(
1410        &self,
1411        path: String,
1412        options: OpenOptions,
1413    ) -> std::result::Result<std::sync::Arc<dyn OpenedFile>, wasmer_bus::abi::BusError> {
1414        FileSystemClient::blocking_open(self, path, options)
1415    }
1416    fn as_client(&self) -> Option<FileSystemClient> {
1417        Some(self.clone())
1418    }
1419}
1420
1421#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
1422pub struct OpenedFileMetaRequest {}
1423#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
1424pub struct OpenedFileUnlinkRequest {}
1425#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
1426pub struct OpenedFileSetLenRequest {
1427    pub len: u64,
1428}
1429#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
1430pub struct OpenedFileIoRequest {}
1431#[wasmer_bus::async_trait]
1432pub trait OpenedFile
1433where
1434    Self: std::fmt::Debug + Send + Sync,
1435{
1436    async fn meta(&self) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError>;
1437    async fn unlink(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError>;
1438    async fn set_len(&self, len: u64)
1439        -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError>;
1440    async fn io(&self) -> std::result::Result<std::sync::Arc<dyn FileIO>, wasmer_bus::abi::BusError>;
1441    fn blocking_meta(&self) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError>;
1442    fn blocking_unlink(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError>;
1443    fn blocking_set_len(
1444        &self,
1445        len: u64,
1446    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError>;
1447    fn blocking_io(
1448        &self,
1449    ) -> std::result::Result<std::sync::Arc<dyn FileIO>, wasmer_bus::abi::BusError>;
1450    fn as_client(&self) -> Option<OpenedFileClient>;
1451}
1452#[wasmer_bus::async_trait]
1453pub trait OpenedFileSimplified
1454where
1455    Self: std::fmt::Debug + Send + Sync,
1456{
1457    async fn meta(&self) -> FsResult<Metadata>;
1458    async fn unlink(&self) -> FsResult<()>;
1459    async fn set_len(&self, len: u64) -> FsResult<()>;
1460    async fn io(&self) -> std::result::Result<std::sync::Arc<dyn FileIO>, wasmer_bus::abi::BusError>;
1461}
1462#[wasmer_bus::async_trait]
1463impl<T> OpenedFile for T
1464where
1465    T: OpenedFileSimplified,
1466{
1467    async fn meta(&self) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1468        Ok(OpenedFileSimplified::meta(self).await)
1469    }
1470    fn blocking_meta(&self) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1471        Ok(wasmer_bus::task::block_on(OpenedFileSimplified::meta(self)))
1472    }
1473    async fn unlink(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1474        Ok(OpenedFileSimplified::unlink(self).await)
1475    }
1476    fn blocking_unlink(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1477        Ok(wasmer_bus::task::block_on(OpenedFileSimplified::unlink(self)))
1478    }
1479    async fn set_len(
1480        &self,
1481        len: u64,
1482    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1483        Ok(OpenedFileSimplified::set_len(self, len).await)
1484    }
1485    fn blocking_set_len(
1486        &self,
1487        len: u64,
1488    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1489        Ok(wasmer_bus::task::block_on(OpenedFileSimplified::set_len(
1490            self, len,
1491        )))
1492    }
1493    async fn io(&self) -> std::result::Result<std::sync::Arc<dyn FileIO>, wasmer_bus::abi::BusError> {
1494        OpenedFileSimplified::io(self).await
1495    }
1496    fn blocking_io(
1497        &self,
1498    ) -> std::result::Result<std::sync::Arc<dyn FileIO>, wasmer_bus::abi::BusError> {
1499        wasmer_bus::task::block_on(OpenedFileSimplified::io(self))
1500    }
1501    fn as_client(&self) -> Option<OpenedFileClient> {
1502        None
1503    }
1504}
1505#[derive(Debug, Clone)]
1506pub struct OpenedFileService {}
1507impl OpenedFileService {
1508    #[allow(dead_code)]
1509    pub(crate) fn attach(
1510        wasm_me: std::sync::Arc<dyn OpenedFile>,
1511        call_handle: wasmer_bus::abi::CallHandle,
1512    ) {
1513        {
1514            let wasm_me = wasm_me.clone();
1515            let call_handle = call_handle.clone();
1516            wasmer_bus::task::respond_to(
1517                call_handle,
1518                wasmer_bus::abi::SerializationFormat::Json,
1519                #[allow(unused_variables)]
1520                move |wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: OpenedFileMetaRequest| {
1521                    let wasm_me = wasm_me.clone();
1522                    async move {
1523                        match wasm_me.meta().await {
1524                            Ok(res) => wasmer_bus::abi::RespondActionTyped::Response(res),
1525                            Err(err) => wasmer_bus::abi::RespondActionTyped::Fault(err)
1526                        }
1527                    }
1528                },
1529            );
1530        }
1531        {
1532            let wasm_me = wasm_me.clone();
1533            let call_handle = call_handle.clone();
1534            wasmer_bus::task::respond_to(
1535                call_handle,
1536                wasmer_bus::abi::SerializationFormat::Json,
1537                #[allow(unused_variables)]
1538                move |wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: OpenedFileUnlinkRequest| {
1539                    let wasm_me = wasm_me.clone();
1540                    async move {
1541                        match wasm_me.unlink().await {
1542                            Ok(res) => wasmer_bus::abi::RespondActionTyped::Response(res),
1543                            Err(err) => wasmer_bus::abi::RespondActionTyped::Fault(err)
1544                        }
1545                    }
1546                },
1547            );
1548        }
1549        {
1550            let wasm_me = wasm_me.clone();
1551            let call_handle = call_handle.clone();
1552            wasmer_bus::task::respond_to(
1553                call_handle,
1554                wasmer_bus::abi::SerializationFormat::Json,
1555                #[allow(unused_variables)]
1556                move |wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: OpenedFileSetLenRequest| {
1557                    let wasm_me = wasm_me.clone();
1558                    let len = wasm_req.len;
1559                    async move {
1560                        match wasm_me.set_len(len).await {
1561                            Ok(res) => wasmer_bus::abi::RespondActionTyped::Response(res),
1562                            Err(err) => wasmer_bus::abi::RespondActionTyped::Fault(err)
1563                        }
1564                    }
1565                },
1566            );
1567        }
1568        {
1569            let wasm_me = wasm_me.clone();
1570            let call_handle = call_handle.clone();
1571            wasmer_bus::task::respond_to(
1572                call_handle,
1573                wasmer_bus::abi::SerializationFormat::Json,
1574                #[allow(unused_variables)]
1575                move |wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: OpenedFileIoRequest| {
1576                    let wasm_me = wasm_me.clone();
1577                    async move {
1578                        match wasm_me.io().await {
1579                            Ok(svc) => {
1580                                FileIOService::attach(svc, wasm_handle);
1581                                wasmer_bus::abi::RespondActionTyped::<()>::Detach
1582                            },
1583                            Err(err) => wasmer_bus::abi::RespondActionTyped::<()>::Fault(err)
1584                        }
1585                    }
1586                },
1587            );
1588        }
1589    }
1590    pub fn listen(wasm_me: std::sync::Arc<dyn OpenedFile>) {
1591        {
1592            let wasm_me = wasm_me.clone();
1593            wasmer_bus::task::listen(
1594                wasmer_bus::abi::SerializationFormat::Json,
1595                #[allow(unused_variables)]
1596                move |_wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: OpenedFileMetaRequest| {
1597                    let wasm_me = wasm_me.clone();
1598                    async move {
1599                        match wasm_me.meta().await {
1600                            Ok(res) => wasmer_bus::abi::ListenActionTyped::Response(res),
1601                            Err(err) => wasmer_bus::abi::ListenActionTyped::Fault(err)
1602                        }
1603                    }
1604                },
1605            );
1606        }
1607        {
1608            let wasm_me = wasm_me.clone();
1609            wasmer_bus::task::listen(
1610                wasmer_bus::abi::SerializationFormat::Json,
1611                #[allow(unused_variables)]
1612                move |_wasm_handle: wasmer_bus::abi::CallHandle,
1613                      wasm_req: OpenedFileUnlinkRequest| {
1614                    let wasm_me = wasm_me.clone();
1615                    async move {
1616                        match wasm_me.unlink().await {
1617                            Ok(res) => wasmer_bus::abi::ListenActionTyped::Response(res),
1618                            Err(err) => wasmer_bus::abi::ListenActionTyped::Fault(err)
1619                        }
1620                    }
1621                },
1622            );
1623        }
1624        {
1625            let wasm_me = wasm_me.clone();
1626            wasmer_bus::task::listen(
1627                wasmer_bus::abi::SerializationFormat::Json,
1628                #[allow(unused_variables)]
1629                move |_wasm_handle: wasmer_bus::abi::CallHandle,
1630                      wasm_req: OpenedFileSetLenRequest| {
1631                    let wasm_me = wasm_me.clone();
1632                    let len = wasm_req.len;
1633                    async move {
1634                        match wasm_me.set_len(len).await {
1635                            Ok(res) => wasmer_bus::abi::ListenActionTyped::Response(res),
1636                            Err(err) => wasmer_bus::abi::ListenActionTyped::Fault(err)
1637                        }
1638                    }
1639                },
1640            );
1641        }
1642        {
1643            let wasm_me = wasm_me.clone();
1644            wasmer_bus::task::listen(
1645                wasmer_bus::abi::SerializationFormat::Json,
1646                #[allow(unused_variables)]
1647                move |wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: OpenedFileIoRequest| {
1648                    let wasm_me = wasm_me.clone();
1649                    async move {
1650                        match wasm_me.io().await {
1651                            Ok(svc) => {
1652                                FileIOService::attach(svc, wasm_handle);
1653                                wasmer_bus::abi::ListenActionTyped::<()>::Detach
1654                            },
1655                            Err(err) => wasmer_bus::abi::ListenActionTyped::<()>::Fault(err)
1656                        }
1657                    }
1658                },
1659            );
1660        }
1661    }
1662    pub fn serve() {
1663        wasmer_bus::task::serve();
1664    }
1665}
1666#[derive(Debug, Clone)]
1667pub struct OpenedFileClient {
1668    ctx: wasmer_bus::abi::CallContext,
1669    task: Option<wasmer_bus::abi::Call>,
1670    join: Option<wasmer_bus::abi::CallJoin<()>>,
1671}
1672impl OpenedFileClient {
1673    pub fn new(wapm: &str) -> Self {
1674        Self {
1675            ctx: wasmer_bus::abi::CallContext::NewBusCall {
1676                wapm: wapm.to_string().into(),
1677                instance: None,
1678            },
1679            task: None,
1680            join: None,
1681        }
1682    }
1683    pub fn new_with_instance(wapm: &str, instance: &str, access_token: &str) -> Self {
1684        Self {
1685            ctx: wasmer_bus::abi::CallContext::NewBusCall {
1686                wapm: wapm.to_string().into(),
1687                instance: Some(wasmer_bus::abi::CallInstance::new(instance, access_token)),
1688            },
1689            task: None,
1690            join: None,
1691        }
1692    }
1693    pub fn attach(handle: wasmer_bus::abi::CallHandle) -> Self {
1694        let handle = wasmer_bus::abi::CallSmartHandle::new(handle);
1695        Self {
1696            ctx: wasmer_bus::abi::CallContext::OwnedSubCall { parent: handle },
1697            task: None,
1698            join: None,
1699        }
1700    }
1701    pub fn wait(self) -> Result<(), wasmer_bus::abi::BusError> {
1702        if let Some(join) = self.join {
1703            join.wait()?;
1704        }
1705        if let Some(task) = self.task {
1706            task.join()?.wait()?;
1707        }
1708        Ok(())
1709    }
1710    pub fn try_wait(&mut self) -> Result<Option<()>, wasmer_bus::abi::BusError> {
1711        if let Some(task) = self.task.take() {
1712            self.join.replace(task.join()?);
1713        }
1714        if let Some(join) = self.join.as_mut() {
1715            join.try_wait()
1716        } else {
1717            Ok(None)
1718        }
1719    }
1720    pub async fn meta(&self) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1721        let request = OpenedFileMetaRequest {};
1722        wasmer_bus::abi::call(
1723            self.ctx.clone(),
1724            wasmer_bus::abi::SerializationFormat::Json,
1725            request,
1726        )
1727        .invoke()
1728        .join()?
1729        .await
1730    }
1731    pub async fn unlink(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1732        let request = OpenedFileUnlinkRequest {};
1733        wasmer_bus::abi::call(
1734            self.ctx.clone(),
1735            wasmer_bus::abi::SerializationFormat::Json,
1736            request,
1737        )
1738        .invoke()
1739        .join()?
1740        .await
1741    }
1742    pub async fn set_len(
1743        &self,
1744        len: u64,
1745    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1746        let request = OpenedFileSetLenRequest { len };
1747        wasmer_bus::abi::call(
1748            self.ctx.clone(),
1749            wasmer_bus::abi::SerializationFormat::Json,
1750            request,
1751        )
1752        .invoke()
1753        .join()?
1754        .await
1755    }
1756    pub async fn io(
1757        &self,
1758    ) -> std::result::Result<std::sync::Arc<dyn FileIO>, wasmer_bus::abi::BusError> {
1759        let request = OpenedFileIoRequest {};
1760        let handle = wasmer_bus::abi::call(
1761            self.ctx.clone(),
1762            wasmer_bus::abi::SerializationFormat::Json,
1763            request,
1764        )
1765        .detach()?;
1766        Ok(Arc::new(FileIOClient::attach(handle)))
1767    }
1768    pub fn blocking_meta(
1769        &self,
1770    ) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1771        wasmer_bus::task::block_on(self.meta())
1772    }
1773    pub fn blocking_unlink(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1774        wasmer_bus::task::block_on(self.unlink())
1775    }
1776    pub fn blocking_set_len(
1777        &self,
1778        len: u64,
1779    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1780        wasmer_bus::task::block_on(self.set_len(len))
1781    }
1782    pub fn blocking_io(
1783        &self,
1784    ) -> std::result::Result<std::sync::Arc<dyn FileIO>, wasmer_bus::abi::BusError> {
1785        wasmer_bus::task::block_on(self.io())
1786    }
1787}
1788impl std::future::Future for OpenedFileClient {
1789    type Output = Result<(), wasmer_bus::abi::BusError>;
1790    fn poll(
1791        mut self: std::pin::Pin<&mut Self>,
1792        cx: &mut std::task::Context<'_>,
1793    ) -> std::task::Poll<Self::Output> {
1794        if let Some(task) = self.task.take() {
1795            self.join.replace(task.join()?);
1796        }
1797        if let Some(join) = self.join.as_mut() {
1798            let join = std::pin::Pin::new(join);
1799            return join.poll(cx);
1800        } else {
1801            std::task::Poll::Ready(Ok(()))
1802        }
1803    }
1804}
1805#[wasmer_bus::async_trait]
1806impl OpenedFile for OpenedFileClient {
1807    async fn meta(&self) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1808        OpenedFileClient::meta(self).await
1809    }
1810    fn blocking_meta(&self) -> std::result::Result<FsResult<Metadata>, wasmer_bus::abi::BusError> {
1811        OpenedFileClient::blocking_meta(self)
1812    }
1813    async fn unlink(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1814        OpenedFileClient::unlink(self).await
1815    }
1816    fn blocking_unlink(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1817        OpenedFileClient::blocking_unlink(self)
1818    }
1819    async fn set_len(
1820        &self,
1821        len: u64,
1822    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1823        OpenedFileClient::set_len(self, len).await
1824    }
1825    fn blocking_set_len(
1826        &self,
1827        len: u64,
1828    ) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1829        OpenedFileClient::blocking_set_len(self, len)
1830    }
1831    async fn io(&self) -> std::result::Result<std::sync::Arc<dyn FileIO>, wasmer_bus::abi::BusError> {
1832        OpenedFileClient::io(self).await
1833    }
1834    fn blocking_io(
1835        &self,
1836    ) -> std::result::Result<std::sync::Arc<dyn FileIO>, wasmer_bus::abi::BusError> {
1837        OpenedFileClient::blocking_io(self)
1838    }
1839    fn as_client(&self) -> Option<OpenedFileClient> {
1840        Some(self.clone())
1841    }
1842}
1843
1844#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
1845pub struct FileIoSeekRequest {
1846    pub from: SeekFrom,
1847}
1848#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
1849pub struct FileIoFlushRequest {}
1850#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
1851pub struct FileIoWriteRequest {
1852    pub data: Vec<u8>,
1853}
1854#[derive(Debug, Clone, serde :: Serialize, serde :: Deserialize)]
1855pub struct FileIoReadRequest {
1856    pub len: u64,
1857}
1858#[wasmer_bus::async_trait]
1859pub trait FileIO
1860where
1861    Self: std::fmt::Debug + Send + Sync,
1862{
1863    async fn seek(
1864        &self,
1865        from: SeekFrom,
1866    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError>;
1867    async fn flush(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError>;
1868    async fn write(
1869        &self,
1870        data: Vec<u8>,
1871    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError>;
1872    async fn read(
1873        &self,
1874        len: u64,
1875    ) -> std::result::Result<FsResult<Vec<u8>>, wasmer_bus::abi::BusError>;
1876    fn blocking_seek(
1877        &self,
1878        from: SeekFrom,
1879    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError>;
1880    fn blocking_flush(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError>;
1881    fn blocking_write(
1882        &self,
1883        data: Vec<u8>,
1884    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError>;
1885    fn blocking_read(
1886        &self,
1887        len: u64,
1888    ) -> std::result::Result<FsResult<Vec<u8>>, wasmer_bus::abi::BusError>;
1889    fn as_client(&self) -> Option<FileIOClient>;
1890}
1891#[wasmer_bus::async_trait]
1892pub trait FileIOSimplified
1893where
1894    Self: std::fmt::Debug + Send + Sync,
1895{
1896    async fn seek(&self, from: SeekFrom) -> FsResult<u64>;
1897    async fn flush(&self) -> FsResult<()>;
1898    async fn write(&self, data: Vec<u8>) -> FsResult<u64>;
1899    async fn read(&self, len: u64) -> FsResult<Vec<u8>>;
1900}
1901#[wasmer_bus::async_trait]
1902impl<T> FileIO for T
1903where
1904    T: FileIOSimplified,
1905{
1906    async fn seek(
1907        &self,
1908        from: SeekFrom,
1909    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError> {
1910        Ok(FileIOSimplified::seek(self, from).await)
1911    }
1912    fn blocking_seek(
1913        &self,
1914        from: SeekFrom,
1915    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError> {
1916        Ok(wasmer_bus::task::block_on(FileIOSimplified::seek(self, from)))
1917    }
1918    async fn flush(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1919        Ok(FileIOSimplified::flush(self).await)
1920    }
1921    fn blocking_flush(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
1922        Ok(wasmer_bus::task::block_on(FileIOSimplified::flush(self)))
1923    }
1924    async fn write(
1925        &self,
1926        data: Vec<u8>,
1927    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError> {
1928        Ok(FileIOSimplified::write(self, data).await)
1929    }
1930    fn blocking_write(
1931        &self,
1932        data: Vec<u8>,
1933    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError> {
1934        Ok(wasmer_bus::task::block_on(FileIOSimplified::write(
1935            self, data,
1936        )))
1937    }
1938    async fn read(
1939        &self,
1940        len: u64,
1941    ) -> std::result::Result<FsResult<Vec<u8>>, wasmer_bus::abi::BusError> {
1942        Ok(FileIOSimplified::read(self, len).await)
1943    }
1944    fn blocking_read(
1945        &self,
1946        len: u64,
1947    ) -> std::result::Result<FsResult<Vec<u8>>, wasmer_bus::abi::BusError> {
1948        Ok(wasmer_bus::task::block_on(FileIOSimplified::read(self, len)))
1949    }
1950    fn as_client(&self) -> Option<FileIOClient> {
1951        None
1952    }
1953}
1954#[derive(Debug, Clone)]
1955pub struct FileIOService {}
1956impl FileIOService {
1957    #[allow(dead_code)]
1958    pub(crate) fn attach(
1959        wasm_me: std::sync::Arc<dyn FileIO>,
1960        call_handle: wasmer_bus::abi::CallHandle,
1961    ) {
1962        {
1963            let wasm_me = wasm_me.clone();
1964            let call_handle = call_handle.clone();
1965            wasmer_bus::task::respond_to(
1966                call_handle,
1967                wasmer_bus::abi::SerializationFormat::Bincode,
1968                #[allow(unused_variables)]
1969                move |wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: FileIoSeekRequest| {
1970                    let wasm_me = wasm_me.clone();
1971                    let from = wasm_req.from;
1972                    async move {
1973                        match wasm_me.seek(from).await {
1974                            Ok(res) => wasmer_bus::abi::RespondActionTyped::Response(res),
1975                            Err(err) => wasmer_bus::abi::RespondActionTyped::Fault(err)
1976                        }
1977                    }
1978                },
1979            );
1980        }
1981        {
1982            let wasm_me = wasm_me.clone();
1983            let call_handle = call_handle.clone();
1984            wasmer_bus::task::respond_to(
1985                call_handle,
1986                wasmer_bus::abi::SerializationFormat::Bincode,
1987                #[allow(unused_variables)]
1988                move |wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: FileIoFlushRequest| {
1989                    let wasm_me = wasm_me.clone();
1990                    async move {
1991                        match wasm_me.flush().await {
1992                            Ok(res) => wasmer_bus::abi::RespondActionTyped::Response(res),
1993                            Err(err) => wasmer_bus::abi::RespondActionTyped::Fault(err)
1994                        }
1995                    }
1996                },
1997            );
1998        }
1999        {
2000            let wasm_me = wasm_me.clone();
2001            let call_handle = call_handle.clone();
2002            wasmer_bus::task::respond_to(
2003                call_handle,
2004                wasmer_bus::abi::SerializationFormat::Bincode,
2005                #[allow(unused_variables)]
2006                move |wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: FileIoWriteRequest| {
2007                    let wasm_me = wasm_me.clone();
2008                    let data = wasm_req.data;
2009                    async move {
2010                        match wasm_me.write(data).await {
2011                            Ok(res) => wasmer_bus::abi::RespondActionTyped::Response(res),
2012                            Err(err) => wasmer_bus::abi::RespondActionTyped::Fault(err)
2013                        }
2014                    }
2015                },
2016            );
2017        }
2018        {
2019            let wasm_me = wasm_me.clone();
2020            let call_handle = call_handle.clone();
2021            wasmer_bus::task::respond_to(
2022                call_handle,
2023                wasmer_bus::abi::SerializationFormat::Bincode,
2024                #[allow(unused_variables)]
2025                move |wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: FileIoReadRequest| {
2026                    let wasm_me = wasm_me.clone();
2027                    let len = wasm_req.len;
2028                    async move {
2029                        match wasm_me.read(len).await {
2030                            Ok(res) => wasmer_bus::abi::RespondActionTyped::Response(res),
2031                            Err(err) => wasmer_bus::abi::RespondActionTyped::Fault(err)
2032                        }
2033                    }
2034                },
2035            );
2036        }
2037    }
2038    pub fn listen(wasm_me: std::sync::Arc<dyn FileIO>) {
2039        {
2040            let wasm_me = wasm_me.clone();
2041            wasmer_bus::task::listen(
2042                wasmer_bus::abi::SerializationFormat::Bincode,
2043                #[allow(unused_variables)]
2044                move |_wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: FileIoSeekRequest| {
2045                    let wasm_me = wasm_me.clone();
2046                    let from = wasm_req.from;
2047                    async move {
2048                        match wasm_me.seek(from).await {
2049                            Ok(res) => wasmer_bus::abi::ListenActionTyped::Response(res),
2050                            Err(err) => wasmer_bus::abi::ListenActionTyped::Fault(err)
2051                        }
2052                    }
2053                },
2054            );
2055        }
2056        {
2057            let wasm_me = wasm_me.clone();
2058            wasmer_bus::task::listen(
2059                wasmer_bus::abi::SerializationFormat::Bincode,
2060                #[allow(unused_variables)]
2061                move |_wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: FileIoFlushRequest| {
2062                    let wasm_me = wasm_me.clone();
2063                    async move {
2064                        match wasm_me.flush().await {
2065                            Ok(res) => wasmer_bus::abi::ListenActionTyped::Response(res),
2066                            Err(err) => wasmer_bus::abi::ListenActionTyped::Fault(err)
2067                        }
2068                    }
2069                },
2070            );
2071        }
2072        {
2073            let wasm_me = wasm_me.clone();
2074            wasmer_bus::task::listen(
2075                wasmer_bus::abi::SerializationFormat::Bincode,
2076                #[allow(unused_variables)]
2077                move |_wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: FileIoWriteRequest| {
2078                    let wasm_me = wasm_me.clone();
2079                    let data = wasm_req.data;
2080                    async move {
2081                        match wasm_me.write(data).await {
2082                            Ok(res) => wasmer_bus::abi::ListenActionTyped::Response(res),
2083                            Err(err) => wasmer_bus::abi::ListenActionTyped::Fault(err)
2084                        }
2085                    }
2086                },
2087            );
2088        }
2089        {
2090            let wasm_me = wasm_me.clone();
2091            wasmer_bus::task::listen(
2092                wasmer_bus::abi::SerializationFormat::Bincode,
2093                #[allow(unused_variables)]
2094                move |_wasm_handle: wasmer_bus::abi::CallHandle, wasm_req: FileIoReadRequest| {
2095                    let wasm_me = wasm_me.clone();
2096                    let len = wasm_req.len;
2097                    async move {
2098                        match wasm_me.read(len).await {
2099                            Ok(res) => wasmer_bus::abi::ListenActionTyped::Response(res),
2100                            Err(err) => wasmer_bus::abi::ListenActionTyped::Fault(err)
2101                        }
2102                    }
2103                },
2104            );
2105        }
2106    }
2107    pub fn serve() {
2108        wasmer_bus::task::serve();
2109    }
2110}
2111#[derive(Debug, Clone)]
2112pub struct FileIOClient {
2113    ctx: wasmer_bus::abi::CallContext,
2114    task: Option<wasmer_bus::abi::Call>,
2115    join: Option<wasmer_bus::abi::CallJoin<()>>,
2116}
2117impl FileIOClient {
2118    pub fn new(wapm: &str) -> Self {
2119        Self {
2120            ctx: wasmer_bus::abi::CallContext::NewBusCall {
2121                wapm: wapm.to_string().into(),
2122                instance: None,
2123            },
2124            task: None,
2125            join: None,
2126        }
2127    }
2128    pub fn new_with_instance(wapm: &str, instance: &str, access_token: &str) -> Self {
2129        Self {
2130            ctx: wasmer_bus::abi::CallContext::NewBusCall {
2131                wapm: wapm.to_string().into(),
2132                instance: Some(wasmer_bus::abi::CallInstance::new(instance, access_token)),
2133            },
2134            task: None,
2135            join: None,
2136        }
2137    }
2138    pub fn attach(handle: wasmer_bus::abi::CallHandle) -> Self {
2139        let handle = wasmer_bus::abi::CallSmartHandle::new(handle);
2140        Self {
2141            ctx: wasmer_bus::abi::CallContext::OwnedSubCall { parent: handle },
2142            task: None,
2143            join: None,
2144        }
2145    }
2146    pub fn wait(self) -> Result<(), wasmer_bus::abi::BusError> {
2147        if let Some(join) = self.join {
2148            join.wait()?;
2149        }
2150        if let Some(task) = self.task {
2151            task.join()?.wait()?;
2152        }
2153        Ok(())
2154    }
2155    pub fn try_wait(&mut self) -> Result<Option<()>, wasmer_bus::abi::BusError> {
2156        if let Some(task) = self.task.take() {
2157            self.join.replace(task.join()?);
2158        }
2159        if let Some(join) = self.join.as_mut() {
2160            join.try_wait()
2161        } else {
2162            Ok(None)
2163        }
2164    }
2165    pub async fn seek(
2166        &self,
2167        from: SeekFrom,
2168    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError> {
2169        let request = FileIoSeekRequest { from };
2170        wasmer_bus::abi::call(
2171            self.ctx.clone(),
2172            wasmer_bus::abi::SerializationFormat::Bincode,
2173            request,
2174        )
2175        .invoke()
2176        .join()?
2177        .await
2178    }
2179    pub async fn flush(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
2180        let request = FileIoFlushRequest {};
2181        wasmer_bus::abi::call(
2182            self.ctx.clone(),
2183            wasmer_bus::abi::SerializationFormat::Bincode,
2184            request,
2185        )
2186        .invoke()
2187        .join()?
2188        .await
2189    }
2190    pub async fn write(
2191        &self,
2192        data: Vec<u8>,
2193    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError> {
2194        let request = FileIoWriteRequest { data };
2195        wasmer_bus::abi::call(
2196            self.ctx.clone(),
2197            wasmer_bus::abi::SerializationFormat::Bincode,
2198            request,
2199        )
2200        .invoke()
2201        .join()?
2202        .await
2203    }
2204    pub async fn read(
2205        &self,
2206        len: u64,
2207    ) -> std::result::Result<FsResult<Vec<u8>>, wasmer_bus::abi::BusError> {
2208        let request = FileIoReadRequest { len };
2209        wasmer_bus::abi::call(
2210            self.ctx.clone(),
2211            wasmer_bus::abi::SerializationFormat::Bincode,
2212            request,
2213        )
2214        .invoke()
2215        .join()?
2216        .await
2217    }
2218    pub fn blocking_seek(
2219        &self,
2220        from: SeekFrom,
2221    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError> {
2222        wasmer_bus::task::block_on(self.seek(from))
2223    }
2224    pub fn blocking_flush(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
2225        wasmer_bus::task::block_on(self.flush())
2226    }
2227    pub fn blocking_write(
2228        &self,
2229        data: Vec<u8>,
2230    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError> {
2231        wasmer_bus::task::block_on(self.write(data))
2232    }
2233    pub fn blocking_read(
2234        &self,
2235        len: u64,
2236    ) -> std::result::Result<FsResult<Vec<u8>>, wasmer_bus::abi::BusError> {
2237        wasmer_bus::task::block_on(self.read(len))
2238    }
2239}
2240impl std::future::Future for FileIOClient {
2241    type Output = Result<(), wasmer_bus::abi::BusError>;
2242    fn poll(
2243        mut self: std::pin::Pin<&mut Self>,
2244        cx: &mut std::task::Context<'_>,
2245    ) -> std::task::Poll<Self::Output> {
2246        if let Some(task) = self.task.take() {
2247            self.join.replace(task.join()?);
2248        }
2249        if let Some(join) = self.join.as_mut() {
2250            let join = std::pin::Pin::new(join);
2251            return join.poll(cx);
2252        } else {
2253            std::task::Poll::Ready(Ok(()))
2254        }
2255    }
2256}
2257#[wasmer_bus::async_trait]
2258impl FileIO for FileIOClient {
2259    async fn seek(
2260        &self,
2261        from: SeekFrom,
2262    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError> {
2263        FileIOClient::seek(self, from).await
2264    }
2265    fn blocking_seek(
2266        &self,
2267        from: SeekFrom,
2268    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError> {
2269        FileIOClient::blocking_seek(self, from)
2270    }
2271    async fn flush(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
2272        FileIOClient::flush(self).await
2273    }
2274    fn blocking_flush(&self) -> std::result::Result<FsResult<()>, wasmer_bus::abi::BusError> {
2275        FileIOClient::blocking_flush(self)
2276    }
2277    async fn write(
2278        &self,
2279        data: Vec<u8>,
2280    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError> {
2281        FileIOClient::write(self, data).await
2282    }
2283    fn blocking_write(
2284        &self,
2285        data: Vec<u8>,
2286    ) -> std::result::Result<FsResult<u64>, wasmer_bus::abi::BusError> {
2287        FileIOClient::blocking_write(self, data)
2288    }
2289    async fn read(
2290        &self,
2291        len: u64,
2292    ) -> std::result::Result<FsResult<Vec<u8>>, wasmer_bus::abi::BusError> {
2293        FileIOClient::read(self, len).await
2294    }
2295    fn blocking_read(
2296        &self,
2297        len: u64,
2298    ) -> std::result::Result<FsResult<Vec<u8>>, wasmer_bus::abi::BusError> {
2299        FileIOClient::blocking_read(self, len)
2300    }
2301    fn as_client(&self) -> Option<FileIOClient> {
2302        Some(self.clone())
2303    }
2304}