Skip to content

Commit

Permalink
Add Frame::map_data (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpdrsn committed Feb 24, 2023
1 parent 619ba28 commit 7bf321a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions http-body/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ impl<T> Frame<T> {
}
}

/// Maps this frame's data to a different type.
pub fn map_data<F, D>(self, f: F) -> Frame<D>
where
F: FnOnce(T) -> D,
{
match self.kind {
Kind::Data(data) => Frame {
kind: Kind::Data(f(data)),
},
Kind::Trailers(trailers) => Frame {
kind: Kind::Trailers(trailers),
},
}
}

/// Returns whether this is a DATA frame.
pub fn is_data(&self) -> bool {
matches!(self.kind, Kind::Data(..))
Expand Down

0 comments on commit 7bf321a

Please sign in to comment.