Commit 0d927f0
authored
feat(util/full): introduce
fixes #154.
this commit introduces a `http_body_util::Full::into_inner()` method.
this allows callers to consume a `Full<D>`, and reacquire the wrapped
value. this matches the style of [many interfaces][into-inner-docs]
offered by various types provided in `core` and `std` such as `Box<T>`,
`Arc<T>`, `Mutex<T>`, as well as [many interfaces][tokio-into-inner-docs]
offered by various types in `tokio` such as `BufWriter<T>`,
`OnceCell<T>`, and so forth.
this pattern is also mirrored in other `http_body_util` types including
`Either<L, R>`.
```rust
use http_body_util::Full;
const DATA: &[u8] = b"hello";
let full = Full::new(DATA);
assert_eq!(full.into_inner(), Some("hello").map(str::as_bytes));
```
NB: an `Full::inner()` method is not provided here. other types in `std`
and `tokio` do not expose such a method. idiomatically, once a chunk
is placed into a `Full<T>` it should be thought of as a `Body` rather
than a `T`, and `inner()` would make this a leaky abstraction.
[into-inner-docs]: https://doc.rust-lang.org/stable/std/?search=into_inner
[tokio-into-inner-docs]: https://docs.rs/tokio/latest/tokio/?search=into_inner
Signed-off-by: katelyn martin <[email protected]>Full::into_inner() (#155)1 parent 740614b commit 0d927f0
1 file changed
+41
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
32 | 50 | | |
33 | 51 | | |
34 | 52 | | |
| |||
144 | 162 | | |
145 | 163 | | |
146 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
147 | 188 | | |
0 commit comments