Skip to content

Commit

Permalink
Change generated functions signatures to remove type parameters; fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shizzard committed Apr 26, 2024
1 parent 6914543 commit 65e9e85
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 134 deletions.
16 changes: 8 additions & 8 deletions prost-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,19 @@ fn try_message(input: TokenStream) -> Result<TokenStream, Error> {
let expanded = quote! {
impl #impl_generics ::prost::Message for #ident #ty_generics #where_clause {
#[allow(unused_variables)]
fn encode_raw<B>(&self, buf: &mut B) where B: ::prost::bytes::BufMut {
fn encode_raw(&self, buf: &mut impl ::prost::bytes::BufMut) {
#(#encode)*
}

#[allow(unused_variables)]
fn merge_field<B>(
fn merge_field(
&mut self,
tag: u32,
wire_type: ::prost::encoding::WireType,
buf: &mut B,
buf: &mut impl ::prost::bytes::Buf,
ctx: ::prost::encoding::DecodeContext,
) -> ::core::result::Result<(), ::prost::DecodeError>
where B: ::prost::bytes::Buf {
{
#struct_name
match tag {
#(#merge)*
Expand Down Expand Up @@ -463,21 +463,21 @@ fn try_oneof(input: TokenStream) -> Result<TokenStream, Error> {
let expanded = quote! {
impl #impl_generics #ident #ty_generics #where_clause {
/// Encodes the message to a buffer.
pub fn encode<B>(&self, buf: &mut B) where B: ::prost::bytes::BufMut {
pub fn encode(&self, buf: &mut impl ::prost::bytes::BufMut) {
match *self {
#(#encode,)*
}
}

/// Decodes an instance of the message from a buffer, and merges it into self.
pub fn merge<B>(
pub fn merge(
field: &mut ::core::option::Option<#ident #ty_generics>,
tag: u32,
wire_type: ::prost::encoding::WireType,
buf: &mut B,
buf: &mut impl ::prost::bytes::Buf,
ctx: ::prost::encoding::DecodeContext,
) -> ::core::result::Result<(), ::prost::DecodeError>
where B: ::prost::bytes::Buf {
{
match tag {
#(#merge,)*
_ => unreachable!(concat!("invalid ", stringify!(#ident), " tag: {}"), tag),
Expand Down
22 changes: 7 additions & 15 deletions prost/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,22 @@ pub trait Message: Debug + Send + Sync {
///
/// Meant to be used only by `Message` implementations.
#[doc(hidden)]
fn encode_raw<B>(&self, buf: &mut B)
fn encode_raw(&self, buf: &mut impl BufMut)
where
B: BufMut,
Self: Sized;

/// Decodes a field from a buffer, and merges it into `self`.
///
/// Meant to be used only by `Message` implementations.
#[doc(hidden)]
fn merge_field<B>(
fn merge_field(
&mut self,
tag: u32,
wire_type: WireType,
buf: &mut B,
buf: &mut impl Buf,
ctx: DecodeContext,
) -> Result<(), DecodeError>
where
B: Buf,
Self: Sized;

/// Returns the encoded length of the message without a length delimiter.
Expand Down Expand Up @@ -167,22 +165,16 @@ impl<M> Message for Box<M>
where
M: Message,
{
fn encode_raw<B>(&self, buf: &mut B)
where
B: BufMut,
{
fn encode_raw(&self, buf: &mut impl BufMut) {
(**self).encode_raw(buf)
}
fn merge_field<B>(
fn merge_field(
&mut self,
tag: u32,
wire_type: WireType,
buf: &mut B,
buf: &mut impl Buf,
ctx: DecodeContext,
) -> Result<(), DecodeError>
where
B: Buf,
{
) -> Result<(), DecodeError> {
(**self).merge_field(tag, wire_type, buf, ctx)
}
fn encoded_len(&self) -> usize {
Expand Down

0 comments on commit 65e9e85

Please sign in to comment.