feat(rust): extend `Request` and `Response` encode api
@@ -126,7 +126,7 @@ impl<'a> Request<'a> {
Request {
#[cfg(feature = "tag")]
tag: TypeTag,
- id: Id(rand::random()),
+ id: Id::fresh(),
method: Some(method),
path: path.into(),
has_body,
@@ -186,7 +186,7 @@ impl Response {
Response {
#[cfg(feature = "tag")]
tag: TypeTag,
- id: Id(rand::random()),
+ id: Id::fresh(),
re,
status: Some(status),
has_body,
@@ -353,6 +353,12 @@ impl<'a, T: Encode<()>> RequestBuilder<'a, T> {
W: Write,
{
let mut e = Encoder::new(buf);
+ self.encode_with_encoder(&mut e)
+ }
+ pub fn encode_with_encoder<W>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>>
+ where
+ W: Write,
+ {
e.encode(&self.header)?;
if let Some(b) = &self.body {
e.encode(b)?;
@@ -409,6 +415,13 @@ impl<T: Encode<()>> ResponseBuilder<T> {
W: Write,
{
let mut e = Encoder::new(buf);
+ self.encode_with_encoder(&mut e)
+ }
+
+ pub fn encode_with_encoder<W>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>>
+ where
+ W: Write,
+ {
e.encode(&self.header)?;
if let Some(b) = &self.body {
e.encode(b)?;
