sandbox/fidl/
directory.rs

1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use crate::{ConversionError, Directory, RemotableCapability};
6use fidl::endpoints::ClientEnd;
7use fidl_fuchsia_io as fio;
8use std::sync::Arc;
9use vfs::directory::entry::DirectoryEntry;
10use vfs::execution_scope::ExecutionScope;
11use vfs::remote::RemoteLike;
12
13impl Directory {
14    /// Turn the [Directory] into a remote VFS node.
15    pub(crate) fn into_remote(self) -> Arc<impl RemoteLike + DirectoryEntry> {
16        let client_end = ClientEnd::<fio::DirectoryMarker>::from(self);
17        vfs::remote::remote_dir(client_end.into_proxy())
18    }
19}
20
21impl RemotableCapability for Directory {
22    fn try_into_directory_entry(
23        self,
24        _scope: ExecutionScope,
25    ) -> Result<Arc<dyn DirectoryEntry>, ConversionError> {
26        Ok(self.into_remote())
27    }
28}
29
30// These tests only run on target because the vfs library is not generally available on host.
31#[cfg(test)]
32mod tests {}