fuchsia_component_client/
fidl_next.rs

1// Copyright 2025 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
5//! Implementations for new Rust bindings.
6
7use fidl_next::{ClientEnd, Discoverable, ServerEnd};
8
9use super::{Error, SVC_DIR, connect_channel_to_protocol_at_path};
10
11/// Connect to a FIDL protocol using the provided server end and namespace
12/// prefix.
13pub fn connect_server_end_to_protocol_at<P: Discoverable>(
14    server_end: ServerEnd<P>,
15    service_directory_path: &str,
16) -> Result<(), Error> {
17    let protocol_path = format!("{}/{}", service_directory_path, P::PROTOCOL_NAME);
18    connect_channel_to_protocol_at_path(server_end.into_untyped(), &protocol_path)
19}
20
21/// Connect to a FIDL protocol using the provided namespace prefix.
22pub fn connect_to_protocol_at<P: Discoverable>(
23    service_prefix: &str,
24) -> Result<ClientEnd<P>, Error> {
25    let (client_end, server_end) = fidl_next::fuchsia::create_channel();
26    let () = connect_server_end_to_protocol_at(server_end, service_prefix)?;
27    Ok(client_end)
28}
29
30/// Connect to a FIDL protocol in the `/svc` directory of the application's root
31/// namespace.
32pub fn connect_to_protocol<P: Discoverable>() -> Result<ClientEnd<P>, Error> {
33    connect_to_protocol_at(SVC_DIR)
34}