Skip to content

feat: add as_maybe_shared() to HeaderValue#828

Open
martintmk wants to merge 1 commit intohyperium:masterfrom
martintmk:maybe-shared
Open

feat: add as_maybe_shared() to HeaderValue#828
martintmk wants to merge 1 commit intohyperium:masterfrom
martintmk:maybe-shared

Conversation

@martintmk
Copy link
Copy Markdown

@martintmk martintmk commented Apr 17, 2026

Expose the inner Bytes via &dyn Any so callers can downcast and clone the shared handle without copying the underlying data.

This is alternative to #811 and #817 that does not expose any new external APIs while still giving performance-aware adopters the access the underlying Bytes instance.

let val = HeaderValue::from_maybe_shared(bytes::Bytes::from_static(b"hello")).unwrap();

let recovered: Bytes = val
     .as_maybe_shared()
     .downcast_ref::<bytes::Bytes>()
     .unwrap()
     .clone();

Expose the inner Bytes via &dyn Any so callers can downcast and clone
the shared handle without copying the underlying data.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant