---
title: StreamingBody
summary: A streaming HTTP body that can be written to, or appended to from another body.
url: https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/
---

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

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

A streaming HTTP body that can be written to, or appended to from another body.

The interface to this type is very similar to `Body`, however it is write-only, and can only be
created as a result of calling
[`Response::stream_to_client()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/#method-stream_to_client) or
[`Request::send_async_streaming()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/request/struct.Request/#method-send_async_streaming),
or as part of a `CandidateResponse` body transformation.

The most efficient way to write the body is through the [`Write`](https://doc.rust-lang.org/stable/core/io/write/trait.Write.html) implementation. Writes are
buffered, and automatically flushed, but you can call [`Write::flush()`](https://doc.rust-lang.org/stable/core/io/write/Write/fn.flush.html) to explicitly flush the
buffer and cause a new chunk to be written to the client.

A streaming body will be automatically aborted if it goes out of scope without calling
[`finish()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/#method-finish).

## Methods

### abandon

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/body/streaming.rs#41

```rust
fn abandon(self) -> Result<()>
```

Abandon a streaming body handle, indicating an unsuccessful end of the stream.

**Parameters**

- `self`: `Self`

**Returns**

`std::io::Result<()>`

### append

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/body/streaming.rs#70

```rust
fn append(&mut self, other: Body)
```

Append a body onto the end of this streaming body.

This operation is performed in amortized constant time, and so should always be preferred to reading
an entire body and then writing the same contents to another body.

#### Examples

```rust
let mut streaming_body = beresp.stream_to_client();
streaming_body.append(other_body);
```

**Parameters**

- `self`: `&mut Self`
- `other`: `Body`

### finish

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/body/streaming.rs#33

```rust
fn finish(self) -> Result<()>
```

Finish writing to a streaming body handle.

**Parameters**

- `self`: `Self`

**Returns**

`std::io::Result<()>`

## Trait implementations

### impl From<StreamingBodyHandle> for StreamingBody

#### from

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/body/streaming.rs#79

```rust
fn from(handle: StreamingBodyHandle) -> Self
```

**Parameters**

- `handle`: `StreamingBodyHandle`

**Returns**

`Self`

### impl StreamingBodyExt for StreamingBody

#### append_trailer

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/body/streaming.rs#103

```rust
fn append_trailer(&mut self, name: impl ToHeaderName, value: impl ToHeaderValue)
```

**Parameters**

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

#### finish_with_trailers

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/body/streaming.rs#110

```rust
fn finish_with_trailers(self, trailers: &HeaderMap) -> Result<(), Error>
```

**Parameters**

- `self`: `Self`
- `trailers`: `&HeaderMap`

**Returns**

`Result<(), std::io::Error>`

### impl Write for StreamingBody

#### flush

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/body/streaming.rs#97

```rust
fn flush(&mut self) -> Result<()>
```

**Parameters**

- `self`: `&mut Self`

**Returns**

`std::io::Result<()>`

#### write

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/body/streaming.rs#89

```rust
fn write(&mut self, buf: &[u8]) -> Result<usize>
```

**Parameters**

- `self`: `&mut Self`
- `buf`: `&[u8]`

**Returns**

`std::io::Result<usize>`

#### write_vectored

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/body/streaming.rs#93

```rust
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize>
```

**Parameters**

- `self`: `&mut Self`
- `bufs`: `&[std::io::IoSlice]`

**Returns**

`std::io::Result<usize>`

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