spiral-sdk 0.1.10

Rust SDK for Spiral resource and table APIs
Documentation
//! Renewable storage compatibility for generated locations operations.

use spiral_contract::call::CallError;
use uuid::Uuid;

use super::generated::locations::AuthenticatedClient;
pub use crate::api::locations::*;
/// Authenticated operations generated from the service contract.
pub type HttpLocationClient = AuthenticatedClient;

impl AuthenticatedClient {
    /// Obtain a renewable binding, allowing older servers to fall back to storage access on 404.
    pub async fn storage_binding_optional(
        &self,
        location_id: Uuid,
        version_id: Uuid,
    ) -> Result<Option<StorageBinding>, CallError<LocationsError>> {
        match self.storage_binding(location_id, version_id).await {
            Ok(binding) => Ok(Some(binding)),
            Err(CallError::Service(error)) if error.status() == 404 => Ok(None),
            Err(CallError::UnknownRemote(error)) if error.status() == 404 => Ok(None),
            Err(error) => Err(error),
        }
    }
}