---
title: ReplaceBuilder
summary: A builder-style API for configuring a non-transactional replace.
url: https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/struct.ReplaceBuilder/
---

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

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

A builder-style API for configuring a non-transactional replace.

## Methods

### always_use_requested_range

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core/replace.rs#186

```rust
fn always_use_requested_range(self) -> Self
```

Respect the range in `to_stream_with_range` even when the body length is not yet known.

When a cache item is `Found`, the length of the cached item may or may not be known:
- the item may be fully cached;
- the item may be streaming in, but have a known length; or
- the item may be streaming in progressively, **without a known length**.

By default (legacy behavior), if a range is specified but the length is not known,
the contents of the entire item will be provided instead of the requested range.

`always_use_requested_range` indicates any cached item returned by this lookup should provide only the requested range,
regardless of whether the length is known. An invalid range will eventually return a read error, possibly after providing some data.

**NOTE:** In the future, the `always_use_requested_range` behavior will be the default, and this method will be removed.

**Parameters**

- `self`: `Self`

**Returns**

`Self`

### begin

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core/replace.rs#132

```rust
fn begin(self) -> Result<Replace, CacheError>
```

Begin the replace, returning a [`Replace`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/struct.Replace/) for reading the object to be replaced (if it
exists) which is also used to provide the new replacement object.

A [`Replace`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/struct.Replace/) gives access to the existing object, if one is stored, that may be used to
construct the replacement object. Use [`Replace::execute()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/struct.Replace/#method-execute) to get a [`StreamingBody`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/) to
write the replacement object into. The existing object cannot be accessed after calling
[`Replace::execute()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/struct.Replace/#method-execute).

For the replace to complete successfully, the object must be written into the
[`StreamingBody`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/), and then [`StreamingBody::finish()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/#method-finish) must be called. If the
[`StreamingBody`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/) is dropped before calling [`StreamingBody::finish()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/#method-finish), the replacement is
considered incomplete, and any concurrent lookups that may be reading from the object as it
is streamed into the cache may encounter a streaming error.

**Parameters**

- `self`: `Self`

**Returns**

`Result<Replace, CacheError>`

### header

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core/replace.rs#157

```rust
fn header(self, name: impl ToHeaderName, value: impl ToHeaderValue) -> Self
```

Sets a single-value header for looking up an existing object to replace, discarding any
previous values associated with the header `name`.

**Note**: These headers are narrowly useful for implementing cache lookups
incorporating the semantics of the [HTTP `Vary`
header](https://www.rfc-editor.org/rfc/rfc9110#section-12.5.5), but the APIs in
this module are not suitable for HTTP caching out-of-the-box. Future SDK
releases will contain an HTTP Cache API.

The headers act as additional factors in object selection, and the choice of _which_
headers to factor in is determined during insertion, via e.g.
[`crate::cache::core::InsertBuilder::vary_by`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/struct.InsertBuilder/#method-vary_by). A lookup will succeed when there is at least one
cached item that matches lookup's cache key, and all of the lookup's headers included in the cache
items' `vary_by` list match the corresponding headers in that cached item.

A [typical example](https://www.fastly.com/blog/best-practices-using-vary-header)
is a cached HTTP response, where the request had an `Accept-Encoding` header. In that case,
the origin server may or may not decide on a given encoding, and whether that same response is
suitable for a request with a different (or missing) `Accept-Encoding` header is determined
by whether `Accept-Encoding` is listed in `Vary` header in the origin's response.

**Parameters**

- `self`: `Self`
- `name`: `impl ToHeaderName`
- `value`: `impl ToHeaderValue`

**Returns**

`Self`

### header_values

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core/replace.rs#165

```rust
fn header_values<'a>(self, name: impl ToHeaderName, values: impl IntoIterator<Item = &'a HeaderValue>) -> Self
```

Sets a multi-value header for looking up an existing object to replace, discarding any
previous values associated with the header `name`.

**Note**: These headers are narrowly useful for implementing cache lookups
incorporating the semantics of the [HTTP `Vary`
header](https://www.rfc-editor.org/rfc/rfc9110#section-12.5.5), but the APIs in
this module are not suitable for HTTP caching out-of-the-box. Future SDK
releases will contain an HTTP Cache API.

The headers act as additional factors in object selection, and the choice of _which_
headers to factor in is determined during insertion, via e.g.
[`crate::cache::core::InsertBuilder::vary_by`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/struct.InsertBuilder/#method-vary_by). A lookup will succeed when there is at least one
cached item that matches lookup's cache key, and all of the lookup's headers included in the cache
items' `vary_by` list match the corresponding headers in that cached item.

A [typical example](https://www.fastly.com/blog/best-practices-using-vary-header)
is a cached HTTP response, where the request had an `Accept-Encoding` header. In that case,
the origin server may or may not decide on a given encoding, and whether that same response is
suitable for a request with a different (or missing) `Accept-Encoding` header is determined
by whether `Accept-Encoding` is listed in `Vary` header in the origin's response.

**Parameters**

- `self`: `Self`
- `name`: `impl ToHeaderName`
- `values`: `impl IntoIterator<Item = &'a HeaderValue>`

**Returns**

`Self`

### replace_strategy

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core/replace.rs#180

```rust
fn replace_strategy(self, strategy: ReplaceStrategy) -> Self
```

Sets the strategy for performing the replace.

See [`ReplaceStrategy`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/enum.ReplaceStrategy/) for details.

**Parameters**

- `self`: `Self`
- `strategy`: `ReplaceStrategy`

**Returns**

`Self`

## 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>`
