sandbox/
directory.rs

1// Copyright 2023 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::CapabilityBound;
6use core::fmt;
7use fidl::endpoints::ClientEnd;
8use {fidl_fuchsia_component_sandbox as fsandbox, fidl_fuchsia_io as fio};
9
10/// A capability that is a `fuchsia.io` directory.
11///
12/// The directory may optionally be backed by a future that serves its contents.
13pub struct Directory {
14    /// The FIDL representation of this [Directory].
15    client_end: ClientEnd<fio::DirectoryMarker>,
16}
17
18impl Directory {
19    /// Create a new [Directory] capability.
20    ///
21    /// Arguments:
22    ///
23    /// * `client_end` - A `fuchsia.io/Directory` client endpoint.
24    pub fn new(client_end: ClientEnd<fio::DirectoryMarker>) -> Self {
25        Directory { client_end }
26    }
27}
28
29impl CapabilityBound for Directory {
30    fn debug_typename() -> &'static str {
31        "Directory"
32    }
33}
34
35impl fmt::Debug for Directory {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        f.debug_struct("Directory").field("client_end", &self.client_end).finish()
38    }
39}
40
41impl From<ClientEnd<fio::DirectoryMarker>> for Directory {
42    fn from(client_end: ClientEnd<fio::DirectoryMarker>) -> Self {
43        Directory { client_end }
44    }
45}
46
47impl From<Directory> for ClientEnd<fio::DirectoryMarker> {
48    /// Return a channel to the Directory and store the channel in
49    /// the registry.
50    fn from(directory: Directory) -> Self {
51        let Directory { client_end } = directory;
52        client_end
53    }
54}
55
56impl From<Directory> for fsandbox::Capability {
57    fn from(directory: Directory) -> Self {
58        Self::Directory(directory.into())
59    }
60}