1use fidl::endpoints::{create_proxy, ProtocolMarker, ServerEnd};
8use fidl_fuchsia_io as fio;
9
10pub fn open_get_proxy<M>(proxy: &fio::DirectoryProxy, flags: fio::OpenFlags, path: &str) -> M::Proxy
11where
12 M: ProtocolMarker,
13{
14 let (new_proxy, new_server_end) = create_proxy::<M>();
15
16 #[cfg(fuchsia_api_level_at_least = "NEXT")]
17 proxy
18 .deprecated_open(
19 flags,
20 fio::ModeType::empty(),
21 path,
22 ServerEnd::<fio::NodeMarker>::new(new_server_end.into_channel()),
23 )
24 .unwrap();
25 #[cfg(not(fuchsia_api_level_at_least = "NEXT"))]
26 proxy
27 .open(
28 flags,
29 fio::ModeType::empty(),
30 path,
31 ServerEnd::<fio::NodeMarker>::new(new_server_end.into_channel()),
32 )
33 .unwrap();
34
35 new_proxy
36}
37
38pub fn open3_get_proxy<M>(
39 proxy: &fio::DirectoryProxy,
40 flags: fio::Flags,
41 options: &fio::Options,
42 path: &str,
43) -> M::Proxy
44where
45 M: ProtocolMarker,
46{
47 let (new_proxy, new_server_end) = create_proxy::<M>();
48
49 #[cfg(fuchsia_api_level_at_least = "NEXT")]
50 proxy.open(path, flags, options, new_server_end.into_channel()).unwrap();
51 #[cfg(not(fuchsia_api_level_at_least = "NEXT"))]
52 proxy.open3(path, flags, options, new_server_end.into_channel()).unwrap();
53
54 new_proxy
55}
56
57pub trait NodeProxyApi {
66 fn clone(
67 &self,
68 flags: fio::OpenFlags,
69 server_end: ServerEnd<fio::NodeMarker>,
70 ) -> Result<(), fidl::Error>;
71}
72
73pub fn clone_get_proxy<M, Proxy>(proxy: &Proxy, flags: fio::OpenFlags) -> M::Proxy
76where
77 M: ProtocolMarker,
78 Proxy: NodeProxyApi,
79{
80 let (new_proxy, new_server_end) = create_proxy::<M>();
81
82 proxy.clone(flags, new_server_end.into_channel().into()).unwrap();
83
84 new_proxy
85}
86
87impl NodeProxyApi for fio::NodeProxy {
88 fn clone(
89 &self,
90 flags: fio::OpenFlags,
91 server_end: ServerEnd<fio::NodeMarker>,
92 ) -> Result<(), fidl::Error> {
93 #[cfg(fuchsia_api_level_at_least = "26")]
94 return Self::deprecated_clone(self, flags, server_end);
95 #[cfg(not(fuchsia_api_level_at_least = "26"))]
96 return Self::clone(self, flags, server_end);
97 }
98}
99
100impl NodeProxyApi for fio::FileProxy {
101 fn clone(
102 &self,
103 flags: fio::OpenFlags,
104 server_end: ServerEnd<fio::NodeMarker>,
105 ) -> Result<(), fidl::Error> {
106 #[cfg(fuchsia_api_level_at_least = "26")]
107 return Self::deprecated_clone(self, flags, server_end);
108 #[cfg(not(fuchsia_api_level_at_least = "26"))]
109 return Self::clone(self, flags, server_end);
110 }
111}
112
113impl NodeProxyApi for fio::DirectoryProxy {
114 fn clone(
115 &self,
116 flags: fio::OpenFlags,
117 server_end: ServerEnd<fio::NodeMarker>,
118 ) -> Result<(), fidl::Error> {
119 #[cfg(fuchsia_api_level_at_least = "26")]
120 return Self::deprecated_clone(self, flags, server_end);
121 #[cfg(not(fuchsia_api_level_at_least = "26"))]
122 return Self::clone(self, flags, server_end);
123 }
124}