pub struct Bindings { /* private fields */ }Expand description
App-facing entry point for accessing bindings configured via ALIEN_*_BINDING
environment variables.
Construction is synchronous and only validates each configured binding’s JSON
shape (see BindingsProvider::from_env_deferred); the deployment platform,
cloud client configuration, and each binding’s backing client are resolved
lazily, on first use. A first operation against a binding that is not
configured reports BINDING_NOT_CONFIGURED before any platform resolution, so
a zero-environment process still constructs and fails cleanly.
§Examples
This is the canonical usage for a Container/Daemon-shaped app (a long-running resident process that only needs bindings, with no Worker event handlers):
use alien_bindings::Bindings;
use object_store::{path::Path, PutPayload};
let bindings = Bindings::from_env()?;
let storage = bindings.storage("files").await?;
storage
.put(&Path::from("greeting.txt"), PutPayload::from_static(b"hello"))
.await?;Implementations§
Source§impl Bindings
impl Bindings
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Sync-constructs Bindings from the current process environment.
Sourcepub fn from_env_map(env: HashMap<String, String>) -> Result<Self>
pub fn from_env_map(env: HashMap<String, String>) -> Result<Self>
Sync-constructs Bindings from an explicit environment map instead of the process
environment.
This is public for embedders that resolve bindings from a caller-supplied map rather
than std::env — notably the napi addon, which merges std::env::vars() with
per-call overrides before constructing Bindings. It is also what from_env
delegates to and what this module’s tests use to inject ALIEN_*_BINDING variables
(avoiding process-global state that’s unsafe to share across parallel tests).
Sourcepub async fn storage(&self, binding_name: &str) -> Result<Arc<dyn Storage>>
pub async fn storage(&self, binding_name: &str) -> Result<Arc<dyn Storage>>
Loads the object storage binding named binding_name.
The returned handle checks credential freshness before each operation. Native credentials and fresh minted credentials remain cached; a minted provider inside its refresh window is re-minted once under the shared resolver’s single-flight guard.
Sourcepub async fn kv(&self, binding_name: &str) -> Result<Arc<dyn Kv>>
pub async fn kv(&self, binding_name: &str) -> Result<Arc<dyn Kv>>
Loads a key-value binding that refreshes minted credentials before use.
Sourcepub async fn queue(&self, binding_name: &str) -> Result<BoundQueue>
pub async fn queue(&self, binding_name: &str) -> Result<BoundQueue>
Loads a queue binding that refreshes minted credentials before use.
Sourcepub async fn vault(&self, binding_name: &str) -> Result<Arc<dyn Vault>>
pub async fn vault(&self, binding_name: &str) -> Result<Arc<dyn Vault>>
Loads a vault binding that refreshes minted credentials before use.
Sourcepub async fn container(&self, binding_name: &str) -> Result<Arc<dyn Container>>
pub async fn container(&self, binding_name: &str) -> Result<Arc<dyn Container>>
Loads a linked container for read-only service discovery.
Sourcepub async fn postgres(&self, binding_name: &str) -> Result<Arc<dyn Postgres>>
pub async fn postgres(&self, binding_name: &str) -> Result<Arc<dyn Postgres>>
Loads the connection details for a linked Postgres database.
Unlike the other kinds this returns no operations — Postgres has no gRPC service and every backend speaks the same wire protocol, so the handle carries connection details and the application connects with its own driver.
The Local and External backends carry their password inline in the binding environment variable, so their handle is resolved once and then cached.
The three cloud backends carry only a locator for their password and read it from the cloud secret store on every call — their handle is never cached. There is no refreshing wrapper, so a handle keeps the password that was current when it was created and calling this again is what picks up a rotated one. Each call is therefore one secret-store read: hold the returned handle for the lifetime of a connection pool rather than calling this per query.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Bindings
impl !UnwindSafe for Bindings
impl Freeze for Bindings
impl Send for Bindings
impl Sync for Bindings
impl Unpin for Bindings
impl UnsafeUnpin for Bindings
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<K, Q> Comparable<Q> for K
impl<K, Q> Comparable<Q> for K
Source§impl<K, Q> Equivalent<Q> for K
impl<K, Q> Equivalent<Q> for K
Source§fn equivalent(&self, key: &Q) -> bool
fn equivalent(&self, key: &Q) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more