Skip to content

Commit

Permalink
Add try_map_codec
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger committed Sep 29, 2023
1 parent 5abbc48 commit b3b8633
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/framed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,19 @@ impl<T, U> FramedParts<T, U> {
_priv: (),
}
}

/// Changes the codec used in this `FramedParts`.
pub fn try_map_codec<V, F, E>(self, f: F) -> Result<FramedParts<T, V>, E>
where
V: Encoder + Decoder,
F: FnOnce(U) -> Result<V, E>,
{
Ok(FramedParts {
io: self.io,
codec: f(self.codec)?,
read_buffer: self.read_buffer,
write_buffer: self.write_buffer,
_priv: (),
})
}
}

0 comments on commit b3b8633

Please sign in to comment.