Skip to main content

xdk/
lib.rs

1#![doc = include_str!("../README.md")]
2#![deny(missing_docs)]
3// The three `REDIRECT_URI` unit tests need edition 2024's `unsafe { set_var }`
4// (allowlisted in the env-mutation guard), so the ban covers every build an
5// embedder compiles and leaves the test build alone.
6#![cfg_attr(not(test), forbid(unsafe_code))]
7#![warn(missing_debug_implementations)]
8// docs.rs passes `--cfg docsrs` on nightly, where `doc_cfg` renders a feature
9// badge on every gated item; stable never sees the feature gate.
10#![cfg_attr(docsrs, feature(doc_cfg))]
11
12// reqwest compiles without a TLS backend and only fails at the first https
13// request, with an error that never mentions TLS; failing the build names
14// the fix instead.
15#[cfg(not(any(feature = "rustls", feature = "native-tls")))]
16compile_error!(
17    "xdk-rs needs a TLS backend: enable the `rustls` feature (on by default) or `native-tls`, \
18     for example `xdk-rs = { version = \"0.1\", default-features = false, features = [\"native-tls\"] }`"
19);
20
21pub mod api;
22pub mod auth;
23pub mod config;
24pub mod error;
25pub mod store;
26#[cfg(feature = "testing")]
27#[cfg_attr(docsrs, doc(cfg(feature = "testing")))]
28pub mod testing;
29
30pub use error::{Error, Result};
31
32/// Fails the build when `$t` stops being shareable across tasks and threads.
33///
34/// Invoked beside each type it guards, so the failure surfaces there rather
35/// than at a distant call site. Exported so the `xr` crate guards its own
36/// types with the same assertion; it is not embedder API.
37#[doc(hidden)]
38#[macro_export]
39macro_rules! assert_send_sync {
40    ($t:ty) => {
41        const _: fn() = || {
42            fn assert<T: Send + Sync>() {}
43            assert::<$t>();
44        };
45    };
46}
47
48// ── Compile-time build and provenance metadata ──────────────────────────
49//
50// API spec consts are read from a checked-in sidecar at
51// `vendor/spec-metadata.json` rather than derived from git context, so
52// the values always describe the actual bytes that ship — uncommitted
53// local refreshes, crates.io tarball installs, and downstream git-pin
54// consumers all see identity that matches the bundled spec.
55//
56// `CRATE_GIT_SHA` is the only field that depends on git context; it
57// resolves to `None` on crates.io tarball builds where `.git` is not
58// present and `Some` on local development and CI builds.
59
60/// Version of this crate, from `[package].version` in `Cargo.toml`.
61pub const CRATE_VERSION: &str = env!("CARGO_PKG_VERSION");
62
63/// Git commit SHA the crate was built from. `None` when the build had
64/// no git context (e.g., `cargo install` from a crates.io tarball,
65/// where `.git` is not present).
66pub const CRATE_GIT_SHA: Option<&'static str> = option_env!("XDK_CRATE_GIT_SHA");
67
68/// X API OpenAPI spec version (`info.version` field) of the vendored
69/// `vendor/x-api-openapi.json` at build time, read from the
70/// `vendor/spec-metadata.json` sidecar. X bumps spec content without
71/// bumping this field; pair with [`API_SPEC_SHA256`] when drift detection
72/// matters.
73pub const API_SPEC_VERSION: &str = env!("XDK_API_SPEC_VERSION");
74
75/// SHA-256 of `vendor/x-api-openapi.json` at the time of its most recent
76/// vendoring, read from `vendor/spec-metadata.json`. Drift-sensitive
77/// identifier — changes every time X changes spec content, regardless of
78/// [`API_SPEC_VERSION`].
79pub const API_SPEC_SHA256: &str = env!("XDK_API_SPEC_SHA256");
80
81/// Date (UTC, `YYYY-MM-DD`) the vendored OpenAPI spec was last refreshed
82/// by `scripts/refresh-x-openapi.sh`, read from `vendor/spec-metadata.json`.
83pub const API_SPEC_DATE: &str = env!("XDK_API_SPEC_DATE");