The crate seems quite good for the most frequent use cases, but it seems to require several extensions to be truly suitable for all use cases.
- Use case: avoid copies for data that comes from sources other than bytes::Bytes objects for requests/responses that are passed to APIs that don’t need them to live on the heap (e.g. synchronous I/O APIs)
Requirements: support using borrowed strings instead of heap-allocated strings
Suggested design: add a lifetime 'a parameter to Bytes in the bytes crate, ByteStr, and all structures containing ByteStr. When the lifetime is 'static, the structures behaves as the current ones. Otherwise, they can include borrowed pointers with lifetime 'a instead of lifetime 'static
- Use case: using strings already on the heap in structures other than bytes::Bytes that are passed to APIs that don’t need sharing or multithreading support
Requirements: support using non-Arc heap-allocated data, like Rc-based data, boxed data, normal vecs, String, etc.
Solution: replace ByteStr with a T parameter that can be borrowed to an &'a [u8], where 'a is the lifetime introduced in (1); introduce a ByteStr and bytes::Bytes variant that uses Rc instead of Arc, and allow directly using Vec or Cow too.
- Use case: having Decode+Encode always produce the starting byte sequence, implementing transparent proxies that modify the request as little as possible, having an encoder that can produce all the byte sequences that decode to a logical request/response
Requirements: whitespace, case for case-insensitive strings, leading zeros and redundant plus signs for numbers that can have them, exact ordering for lists and other non-semantic characteristics need to be recorded
Solution: add FormattedRequest, FormattedResponse structs that include such data and are convertible or include Request/Response
- Use case: interoperability of body handling between libraries (including support for chunked encoding and in general streaming)
Requirements: provide guidance on what the T for body should be set to, possibly including some structures to use there OR replace T with something more structured
- Use case: support using websockets
Requirements: websocket-related structures are provided, ws and wss protocols in Uri, etc.