spin_sdk/variables.rs
1//! Component configuration variables.
2//!
3//! Component variables must be defined in the application
4//! manifest, in the `[component.<name>.variables]` section.
5//! Component variables typically use template syntax to
6//! derive values from application variables, which are
7//! the only variables that may be overridden directly (for
8//! example, on the Spin command line).
9//!
10//! # Examples
11//!
12//! Get the value of a component variable.
13//!
14//! ```no_run
15//! # fn main() -> anyhow::Result<()> {
16//! let region = spin_sdk::variables::get("region_id")?;
17//! let regional_url = format!("https://{region}.db.example.com");
18//! # Ok(())
19//! # }
20//! ```
21//!
22//! Fail gracefully if a variable is not set.
23//!
24//! ```no_run
25//! use spin_sdk::variables::Error;
26//!
27//! # fn main() -> anyhow::Result<()> {
28//! let favourite = match spin_sdk::variables::get("favourite") {
29//! Ok(value) => value,
30//! Err(Error::Undefined(_)) => "not playing favourites".to_owned(),
31//! Err(e) => anyhow::bail!(e),
32//! };
33//! # Ok(())
34//! # }
35//! ```
36
37/// Get the value of a component variable.
38///
39/// # Examples
40///
41/// Get the value of a component variable.
42///
43/// ```no_run
44/// # fn main() -> anyhow::Result<()> {
45/// let region = spin_sdk::variables::get("region_id")?;
46/// let regional_url = format!("https://{region}.db.example.com");
47/// # Ok(())
48/// # }
49/// ```
50///
51/// Fail gracefully if a variable is not set.
52///
53/// ```no_run
54/// use spin_sdk::variables::Error;
55///
56/// # fn main() -> anyhow::Result<()> {
57/// let favourite = match spin_sdk::variables::get("favourite") {
58/// Ok(value) => value,
59/// Err(Error::Undefined(_)) => "not playing favourites".to_owned(),
60/// Err(e) => anyhow::bail!(e),
61/// };
62/// # Ok(())
63/// # }
64/// ```
65#[doc(inline)]
66pub use super::wit::v2::variables::get;
67
68#[doc(inline)]
69pub use super::wit::v2::variables::Error;