Skip to content

Conversation

@cratelyn
Copy link
Member

this commit introduces clone and copy implementations for the
EosRef<'a, E> type used to inspect and classify the outcome of a
request or response body.

as the documentation comment notes in the commit below, this enum only
contains immutable references to other values: a header map or an
error. other variants are empty tags.

pub enum EosRef<'a, E = Error> {
    None,
    Trailers(&'a HeaderMap),
    Error(&'a E),
    Cancelled,
}

this commit makes this type implicitly clonable.

Signed-off-by: katelyn martin [email protected]

@cratelyn cratelyn self-assigned this Nov 19, 2025
this commit introduces clone and copy implementations for the
`EosRef<'a, E>` type used to inspect and classify the outcome of a
request or response body.

as the documentation comment notes in the commit below, this enum only
contains immutable references to other values: a header map or an
error. other variants are empty tags.

```rust
pub enum EosRef<'a, E = Error> {
    None,
    Trailers(&'a HeaderMap),
    Error(&'a E),
    Cancelled,
}
```

this commit makes this type implicitly clonable.

Signed-off-by: katelyn martin <[email protected]>
@cratelyn cratelyn force-pushed the kate/http-body-eos.add-clone-and-copy branch from c043c97 to 7b36b44 Compare November 19, 2025 18:40
Comment on lines +136 to +143
/// A reference to the end of a stream can be cheaply cloned.
///
/// Each of the variants are empty tags, or immutable references.
impl<'a, E> Clone for EosRef<'a, E> {
fn clone(&self) -> Self {
*self
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://gist.github.com/cratelyn/ff1e2d4299ae2626c229dc31aa21597b

#[derive(Clone)] will only work if E: Clone. this is manually implemented because we want this reference to be clonable even if E: Clone does not hold.

@cratelyn
Copy link
Member Author

see #4246, where this "end of stream" middleware was previously introduced.

@cratelyn cratelyn marked this pull request as ready for review November 19, 2025 19:07
@cratelyn cratelyn requested a review from a team as a code owner November 19, 2025 19:07
@cratelyn
Copy link
Member Author

see #4306, which builds upon this change to make further use of our EosRef<'a, E> model in our stream labeling facilities.

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.

2 participants