sl4f_lib/common_utils/
fidl.rs1use anyhow::Error;
5use fidl::endpoints::{ClientEnd, ProtocolMarker};
6
7use glob::glob;
8
9pub fn connect_in_paths<T: ProtocolMarker>(glob_paths: &[&str]) -> Result<Option<T::Proxy>, Error> {
14 let proxy = glob_paths
15 .iter()
16 .map(|glob_path| {
17 let found_path = glob(glob_path)?.find_map(Result::ok);
18 match found_path {
19 Some(path) => {
20 let (client, server) = zx::Channel::create();
21 fdio::service_connect(path.to_string_lossy().as_ref(), server)?;
22 let client_end = ClientEnd::<T>::new(client);
23 Ok(Some(client_end.into_proxy()))
24 }
25 None => Ok(None),
26 }
27 })
28 .collect::<Result<Vec<Option<T::Proxy>>, Error>>()?
29 .into_iter()
30 .find(|proxy| proxy.is_some())
31 .flatten();
32 Ok(proxy)
33}