use fidl::endpoints::{create_proxy, ProtocolMarker, ServerEnd};
use fidl_fuchsia_io as fio;
pub fn open_get_proxy<M>(proxy: &fio::DirectoryProxy, flags: fio::OpenFlags, path: &str) -> M::Proxy
where
M: ProtocolMarker,
{
let (new_proxy, new_server_end) = create_proxy::<M>();
proxy
.open(
flags,
fio::ModeType::empty(),
path,
ServerEnd::<fio::NodeMarker>::new(new_server_end.into_channel()),
)
.unwrap();
new_proxy
}
pub fn open3_get_proxy<M>(
proxy: &fio::DirectoryProxy,
flags: fio::Flags,
options: &fio::Options,
path: &str,
) -> M::Proxy
where
M: ProtocolMarker,
{
let (new_proxy, new_server_end) = create_proxy::<M>();
proxy.open3(path, flags, options, new_server_end.into_channel()).unwrap();
new_proxy
}
pub trait NodeProxyApi {
fn clone(
&self,
flags: fio::OpenFlags,
server_end: ServerEnd<fio::NodeMarker>,
) -> Result<(), fidl::Error>;
}
pub fn clone_get_proxy<M, Proxy>(proxy: &Proxy, flags: fio::OpenFlags) -> M::Proxy
where
M: ProtocolMarker,
Proxy: NodeProxyApi,
{
let (new_proxy, new_server_end) = create_proxy::<M>();
proxy.clone(flags, new_server_end.into_channel().into()).unwrap();
new_proxy
}
impl NodeProxyApi for fio::NodeProxy {
fn clone(
&self,
flags: fio::OpenFlags,
server_end: ServerEnd<fio::NodeMarker>,
) -> Result<(), fidl::Error> {
#[cfg(fuchsia_api_level_at_least = "NEXT")]
return Self::deprecated_clone(self, flags, server_end);
#[cfg(not(fuchsia_api_level_at_least = "NEXT"))]
return Self::clone(self, flags, server_end);
}
}
impl NodeProxyApi for fio::FileProxy {
fn clone(
&self,
flags: fio::OpenFlags,
server_end: ServerEnd<fio::NodeMarker>,
) -> Result<(), fidl::Error> {
#[cfg(fuchsia_api_level_at_least = "NEXT")]
return Self::deprecated_clone(self, flags, server_end);
#[cfg(not(fuchsia_api_level_at_least = "NEXT"))]
return Self::clone(self, flags, server_end);
}
}
impl NodeProxyApi for fio::DirectoryProxy {
fn clone(
&self,
flags: fio::OpenFlags,
server_end: ServerEnd<fio::NodeMarker>,
) -> Result<(), fidl::Error> {
#[cfg(fuchsia_api_level_at_least = "NEXT")]
return Self::deprecated_clone(self, flags, server_end);
#[cfg(not(fuchsia_api_level_at_least = "NEXT"))]
return Self::clone(self, flags, server_end);
}
}