---
title: KVStore
summary: A Compute KV Store.
url: https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.KVStore/
---

**Kind:** Struct  
**Module:** [fastly](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/)  
**Package:** fastly 0.13.1  
**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/kv_store.rs#576

```rust
pub struct KVStore { /* private fields */ }
```

A [Compute KV Store](https://www.fastly.com/blog/introducing-the-compute-edge-kv-store-global-persistent-storage-for-compute-functions).

Keys in the KV Store must follow the following rules:

  * Keys can contain any sequence of valid Unicode characters, of length 1-1024 bytes when
    UTF-8 encoded.
  * Keys cannot contain Carriage Return or Line Feed characters.
  * Keys cannot start with `.well-known/acme-challenge/`.
  * Keys cannot be named `.` or `..`.

## Methods

### build_delete

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/kv_store.rs#681

```rust
fn build_delete(&self) -> DeleteBuilder<'_>
```

Create a buildable delete request for the KV Store.

When the desired configuration has been set, execute the delete and wait for the response.

**Parameters**

- `self`: `&Self`

**Returns**

`DeleteBuilder`

### build_insert

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/kv_store.rs#649

```rust
fn build_insert(&self) -> InsertBuilder<'_>
```

Create a buildable insert request for the KV Store.

When the desired configuration has been set, execute the insert and wait for the response.

**Parameters**

- `self`: `&Self`

**Returns**

`InsertBuilder`

### build_list

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/kv_store.rs#709

```rust
fn build_list(&self) -> ListBuilder<'_>
```

Create a buildable list request for the KV Store.

When the desired configuration has been set, execute the list and wait for the response.

**Parameters**

- `self`: `&Self`

**Returns**

`ListBuilder`

### build_lookup

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/kv_store.rs#608

```rust
fn build_lookup(&self) -> LookupBuilder<'_>
```

Create a buildable lookup request for the KV Store.

When the desired configuration has been set, execute the lookup and wait for the response.

**Parameters**

- `self`: `&Self`

**Returns**

`LookupBuilder`

### delete

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/kv_store.rs#674

```rust
fn delete(&self, key: &str) -> Result<(), KVStoreError>
```

Delete a value in the KV Store.

Returns `Ok(())` if delete is successful.

**Parameters**

- `self`: `&Self`
- `key`: `&str`

**Returns**

`Result<(), KVStoreError>`

### insert

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/kv_store.rs#634

```rust
fn insert(&self, key: &str, value: impl Into<Body>) -> Result<(), KVStoreError>
```

Insert a value into the KV Store.

If the store already contained a value for this key, it will be overwritten.

The value may be provided as any type that can be converted to [`Body`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/), such as `&[u8]`,
`Vec<u8>`, `&str`, or `String`.

#### Value sizes

The size of the value must be known when calling this method. In practice, that means that
if a [`Body`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.Body/) value contains an external request or response, it must be encoded with
`Content-Length` rather than `Transfer-Encoding: chunked`.

**Parameters**

- `self`: `&Self`
- `key`: `&str`
- `value`: `impl Into<Body>`

**Returns**

`Result<(), KVStoreError>`

### list

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/kv_store.rs#700

```rust
fn list(&self) -> Result<ListPage, KVStoreError>
```

List keys in the KV Store.

Returns an `Ok(ListPage)` on success, and `Err(KVStoreError)` if there was a failure. The
limit of items per page defaults to 100 items, but can be configured through [`ListBuilder`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/kv_store/struct.ListBuilder/).

**Parameters**

- `self`: `&Self`

**Returns**

`Result<ListPage, KVStoreError>`

### lookup

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/kv_store.rs#600

```rust
fn lookup(&self, key: &str) -> Result<LookupResponse, KVStoreError>
```

Look up a value in the KV Store.

Returns `Ok(LookupResponse)` if the value is retrieved without error, and `KVStoreError` if the lookup failed.

**Parameters**

- `self`: `&Self`
- `key`: `&str`

**Returns**

`Result<LookupResponse, KVStoreError>`

### open

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/kv_store.rs#590

```rust
fn open(name: &str) -> Result<Option<Self>, KVStoreError>
```

Open the KV Store with the given name.

If there is no store by that name, this returns `Ok(None)`.

**Parameters**

- `name`: `&str`

**Returns**

`Result<Option<Self>, KVStoreError>`

### pending_delete_wait

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/kv_store.rs#688

```rust
fn pending_delete_wait(&self, pending_delete_handle: PendingDeleteHandle) -> Result<(), KVStoreError>
```

Delete a value in the KV Store.

Returns `Ok(())` if the key is deleted, and `KVStoreError` if the key was not found.

**Parameters**

- `self`: `&Self`
- `pending_delete_handle`: `PendingDeleteHandle`

**Returns**

`Result<(), KVStoreError>`

### pending_insert_wait

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/kv_store.rs#663

```rust
fn pending_insert_wait(&self, pending_insert_handle: PendingInsertHandle) -> Result<(), KVStoreError>
```

Insert a value in the KV Store.

Returns `Ok(())` if the value is found, and `KVStoreError` if the key was not found.

**Parameters**

- `self`: `&Self`
- `pending_insert_handle`: `PendingInsertHandle`

**Returns**

`Result<(), KVStoreError>`

### pending_list_wait

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/kv_store.rs#722

```rust
fn pending_list_wait(&self, pending_request_handle: PendingListHandle) -> Result<ListPage, KVStoreError>
```

Wait on a pending list operation.

Returns `Ok(ListPage)` on success, and `Err(KVStoreError)` if there was a failure.

**Parameters**

- `self`: `&Self`
- `pending_request_handle`: `PendingListHandle`

**Returns**

`Result<ListPage, KVStoreError>`

### pending_lookup_wait

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/kv_store.rs#615

```rust
fn pending_lookup_wait(&self, pending_request_handle: PendingLookupHandle) -> Result<LookupResponse, KVStoreError>
```

Look up a value in the KV Store.

Returns `Ok(LookupResponse)` if the value is found, and `Err(KVStoreError)` if the lookup failed.

**Parameters**

- `self`: `&Self`
- `pending_request_handle`: `PendingLookupHandle`

**Returns**

`Result<LookupResponse, KVStoreError>`

## Auto trait implementations

- `Freeze`
- `RefUnwindSafe`
- `Send`
- `Sync`
- `Unpin`
- `UnsafeUnpin`
- `UnwindSafe`

## Blanket implementations

- `Any`
- `Borrow<T>`
- `BorrowMut<T>`
- `Downcast`
- `DowncastSync`
- `ErasedDestructor`
- `From<T>`
- `Into<U>`
- `IntoEither`
- `Same`
- `TryFrom<U>`
- `TryInto<U>`
