Add Resp::into_parts
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing

This commit is contained in:
Alex 2022-07-22 13:40:06 +02:00
parent b9df442f03
commit 67ea3a48fa
Signed by: lx
GPG key ID: 0E496D15096376BE

View file

@ -63,10 +63,6 @@ pub struct Req<M: Message> {
} }
impl<M: Message> Req<M> { impl<M: Message> Req<M> {
pub fn msg(&self) -> &M {
&self.msg
}
pub fn with_fixed_body(self, b: Bytes) -> Self { pub fn with_fixed_body(self, b: Bytes) -> Self {
Self { Self {
body: BodyData::Fixed(b), body: BodyData::Fixed(b),
@ -81,6 +77,10 @@ impl<M: Message> Req<M> {
} }
} }
pub fn msg(&self) -> &M {
&self.msg
}
pub fn take_stream(&mut self) -> Option<ByteStream> { pub fn take_stream(&mut self) -> Option<ByteStream> {
std::mem::replace(&mut self.body, BodyData::None).into_stream() std::mem::replace(&mut self.body, BodyData::None).into_stream()
} }
@ -216,6 +216,10 @@ impl<M: Message> Resp<M> {
self.msg self.msg
} }
pub fn into_parts(self) -> (M::Response, Option<ByteStream>) {
(self.msg, self.body.into_stream())
}
pub(crate) fn into_enc(self) -> Result<RespEnc, rmp_serde::encode::Error> { pub(crate) fn into_enc(self) -> Result<RespEnc, rmp_serde::encode::Error> {
Ok(RespEnc::Success { Ok(RespEnc::Success {
msg: rmp_to_vec_all_named(&self.msg)?.into(), msg: rmp_to_vec_all_named(&self.msg)?.into(),