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, WeakInstanceToken};
6use fidl::endpoints::ClientEnd;
7use std::sync::Arc;
8use vfs::directory::entry::DirectoryEntry;
9use vfs::execution_scope::ExecutionScope;
10use vfs::remote::RemoteLike;
11use {fidl_fuchsia_component_sandbox as fsandbox, fidl_fuchsia_io as fio};
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 crate::fidl::IntoFsandboxCapability for crate::Directory {
22    fn into_fsandbox_capability(self, _token: WeakInstanceToken) -> fsandbox::Capability {
23        fsandbox::Capability::Directory(self.into())
24    }
25}
26impl RemotableCapability for Directory {
27    fn try_into_directory_entry(
28        self,
29        _scope: ExecutionScope,
30        _token: WeakInstanceToken,
31    ) -> Result<Arc<dyn DirectoryEntry>, ConversionError> {
32        Ok(self.into_remote())
33    }
34}
35
36// These tests only run on target because the vfs library is not generally available on host.
37#[cfg(test)]
38mod tests {}