Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change generated functions signatures to remove type parameters #1045

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
Loading