1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! Experimental KV store interfaces for Compute@Edge.
//!
//! This crate contains experimental APIs that are subject to change or removal even in minor
//! versions of this crate. These APIs may not be available for all Compute@Edge services; contact
//! <support@fastly.com> for details.
use fastly_shared::FastlyStatus;

mod handle;
pub mod local_kv;
pub mod object_store;
// TODO ACF 2021-10-07: this is only exposed for integration testing
#[doc(hidden)]
pub mod sys;

pub use self::local_kv::LocalStore;
pub use self::object_store::ObjectStore;

/// Errors that can arise during key-value store operations.
///
/// This type is marked as non-exhaustive because more variants will be added over time.
#[derive(Clone, Debug, Eq, PartialEq, thiserror::Error)]
#[non_exhaustive]
pub enum StoreError {
    /// The key-value store interface is not enabled for this service or on this cache node.
    #[error("Key-value store interface not enabled")]
    NotEnabled,
    /// The key provided for this operation was not valid.
    #[error("Invalid key")]
    InvalidKey,
    /// The store handle provided for this operation was not valid.
    #[error("Invalid store handle")]
    InvalidStoreHandle,
    /// The store by this name did not exist.
    #[error("Unknown store name: {0:?}")]
    UnknownStore(String),
    /// Some unexpected error occurred.
    #[error("unexpected key-value store error: {0:?}")]
    Unexpected(FastlyStatus),
}

impl From<FastlyStatus> for StoreError {
    fn from(st: FastlyStatus) -> Self {
        StoreError::Unexpected(st)
    }
}