Skip to main content

qcs_api_client_grpc/
lib.rs

1// Copyright 2026 Rigetti Computing
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#![allow(clippy::useless_borrows_in_formatting)]
16#![allow(clippy::needless_borrow)]
17#![allow(clippy::derive_partial_eq_without_eq)]
18
19//! This crate provides an autogenerated gRPC client for the QCS API, along with helper utilities for automatically loading
20//! credentials from a user's QCS config and keeping authentication tokens refreshed.
21//!
22//! - [`get_channel`]: create a [`Channel`](qcs_dependencies_client::tonic::transport::Channel) to the given gRPC endpoint with QCS authentication automatically set up.
23//! - [`wrap_channel`]: wrap an existing [`Channel`](qcs_dependencies_client::tonic::transport::Channel) with QCS authentication.
24//!
25//! ## Quick Start
26//!
27//! ```rust
28//! use qcs_api_client_grpc::get_channel;
29//! use qcs_api_client_grpc::services::controller::controller_client::ControllerClient;
30//! use qcs_api_client_grpc::services::translation::translation_client::TranslationClient;
31//!
32//! async fn controller_request() {
33//!     let uri = "example.per-qpu.rigetti.com:50000".parse().unwrap();
34//!     let channel = get_channel(uri).unwrap();
35//!     let mut client = ControllerClient::new(channel);
36//!     // Use the client
37//! }
38//!
39//! fn translation_request() {
40//!     let uri = "example.translation.rigetti.com:50000".parse().unwrap();
41//!     let channel = get_channel(uri).unwrap();
42//!     let mut client = TranslationClient::new(channel);
43//!     // Use the client
44//! }
45//! ```
46//!
47//! # Crate features
48//!
49//! * `server`: include the generated server code for both Controller Service
50//!   and Translation Service
51//! * `regen`: regenerate the protobuf code and store it in `./src/gen`
52//!
53//! By default, both features are disabled.
54
55/// Utilities for creating and working with [`Channel`]s.
56///
57/// This module contains helper code for wrapping a [`Channel`] so that QCS credentials are
58/// automatically used and refreshed as necessary.
59///
60/// Most users will want to use [`get_channel`], [`get_wrapped_channel`], or [`wrap_channel`].
61///
62/// # Generics
63///
64/// The functions for wrapping channels use generics `C: GrpcService<Body>` to accept not only
65/// bare [`Channel`]s but also channels wrapped in middleware like [`RefreshService`] or
66/// [`RetryService`]
67///
68/// # Example
69///
70/// To create a channel that automatically retries on certain errors and refreshes QCS credentials
71/// when authentication fails:
72///
73/// ```no_run
74/// # #[tokio::main]
75/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
76/// use qcs_api_client_grpc::tonic::parse_uri;
77/// use qcs_api_client_grpc::tonic::get_channel;
78/// use qcs_api_client_grpc::tonic::wrap_channel;
79/// use qcs_api_client_grpc::tonic::wrap_channel_with_retry;
80///
81/// let uri = parse_uri("https://api.qcs.rigetti.com")?;
82/// let channel = get_channel(uri)?;
83/// let with_creds = wrap_channel(channel)?;
84/// let with_creds_and_retry = wrap_channel_with_retry(with_creds);
85/// // Use with_creds_and_retry as a gRPC client
86/// # Ok(())
87/// # }
88/// ```
89pub mod tonic;
90
91pub use crate::tonic::{
92    get_channel, get_channel_with_timeout, get_endpoint, get_endpoint_with_timeout,
93    get_wrapped_channel, wrap_channel,
94};
95pub use qcs_api_client_common::configuration as client_configuration;
96
97pub mod models {
98    pub mod controller {
99        include!("gen/models.controller.rs");
100        include!("gen/models.controller.serde.rs");
101    }
102    pub mod translation {
103        include!("gen/models.translation.rs");
104        include!("gen/models.translation.serde.rs");
105    }
106}
107pub mod services {
108    pub mod controller {
109        include!("gen/services.controller.rs");
110        include!("gen/services.controller.serde.rs");
111    }
112    pub mod translation {
113        include!("gen/services.translation.rs");
114        include!("gen/services.translation.serde.rs");
115    }
116}