Expand description
The hand-written runtime the generated Box Rust SDK ships against
(TR-Rust.5). It implements the machine-readable runtime contract
(gantry-contract V1): generated code calls only these declarations, and
this crate supplies the behavior — a retrying async network layer (jittered
backoff, 401 refresh, Retry-After), auth-token threading, request builders,
and response accessors.
It is the real implementation the compilable stubs stand in for during
generation-time verification (FR-5.3). Because it satisfies the same
signatures — async fn network entry points returning Result<T, Error>,
per the Rust manifest axes — the generated SDK compiles against it unchanged
(FR-5.2), which crates/gantry-backend-rust/tests enforces.
Async threads cancellation through the future itself (no context parameter);
dropping a fetch future cancels the in-flight request.
Structs§
- Auth
- The configured authentication flow. Build one with
Auth::developer_token,Auth::client_credentials, orAuth::oauth, then pass it toClient::new. - CcgConfig
- The Client Credentials Grant config: server-to-server auth with no signing
key. Set exactly one subject —
enterprise_idfor the service account, oruser_idto act as a managed user. DerivesDefaultso the optionaluser_id/token_urlcan be elided with..Default::default(). - Client
- The runtime session: it holds the auth flow, HTTP client, base-URL configuration, and retry policy shared by every manager.
- Error
- A runtime error: a failed request, auth acquisition, or body decode. Opaque by design — the message carries the detail, the type stays stable.
- JwtConfig
- JWT server auth config — the fields Box’s
box_config.jsoncarries. Set exactly one subject:enterprise_idfor the service account, oruser_idto act as a managed user. - OAuth
Config - The OAuth 2.0 authorization-code config. Use
OAuthConfig::authorize_urlto build the redirect,OAuthConfig::exchange_codeto turn the returned code into anAuth, orAuth::oauthto resume from a stored refresh token. - Request
- The runtime-owned HTTP request envelope, assembled by the
with_*builders beforefetchexecutes it. - Response
- The runtime-owned HTTP response envelope. The body is read fully so it can be replayed as bytes or a stream and so retries stay safe.
- Stream
- A body stream. Buffered by construction (the Rust manifest’s streaming axis is satisfied by full buffering here): keeping the bytes in hand makes both request retries and response replay safe.
Traits§
- Refresh
Token Store - A durable store for the rotating OAuth refresh token. Box invalidates the previous refresh token on each exchange, so an app that restarts must reload the newest one — implement this to persist each rotation (a file, a DB row, a secret manager).
- Token
Source - A custom access-token source, for callers that need to own token
acquisition and refresh outside the built-in flows — e.g. an
engine-owned token cache with proactive refresh and per-identity fan-out.
Build an
Authfrom one withAuth::custom.
Functions§
- response_
bytes - Read the whole response body.
- response_
header - A response header value, empty when absent (redirect Location, Retry-After surfacing).
- response_
stream - The response body as a stream, for binary downloads (FR-7.4).
- status_
code - The response status code.
- with_
form_ body - Return the request with an application/x-www-form-urlencoded body (the OAuth2 token endpoints).
- with_
header - Return the request with the header set (replacing any prior value).
- with_
json_ body - Return the request with the serialized JSON body and content type set.
- with_
multipart_ body - Return the request with a Box-style multipart body: an
attributesJSON part plus a file part (G-7). - with_
query - Return the request with the query parameter appended, encoded at send time.
- with_
stream_ body - Return the request with a streaming body (buffered here).