Skip to content

Commit 7bf321a

Browse files
authored
Add Frame::map_data (#89)
1 parent 619ba28 commit 7bf321a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

http-body/src/frame.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ impl<T> Frame<T> {
3131
}
3232
}
3333

34+
/// Maps this frame's data to a different type.
35+
pub fn map_data<F, D>(self, f: F) -> Frame<D>
36+
where
37+
F: FnOnce(T) -> D,
38+
{
39+
match self.kind {
40+
Kind::Data(data) => Frame {
41+
kind: Kind::Data(f(data)),
42+
},
43+
Kind::Trailers(trailers) => Frame {
44+
kind: Kind::Trailers(trailers),
45+
},
46+
}
47+
}
48+
3449
/// Returns whether this is a DATA frame.
3550
pub fn is_data(&self) -> bool {
3651
matches!(self.kind, Kind::Data(..))

0 commit comments

Comments
 (0)