Skip to content

Commit

Permalink
chore: Use derive macro to implement default (#1762)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto authored Jun 28, 2024
1 parent 1b3fa89 commit 74d7673
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
10 changes: 2 additions & 8 deletions tonic-web/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,15 @@ use crate::call::content_types::GRPC_WEB;
use crate::call::GrpcWebCall;

/// Layer implementing the grpc-web protocol for clients.
#[derive(Debug, Clone)]
#[derive(Debug, Default, Clone)]
pub struct GrpcWebClientLayer {
_priv: (),
}

impl GrpcWebClientLayer {
/// Create a new grpc-web for clients layer.
pub fn new() -> GrpcWebClientLayer {
Self { _priv: () }
}
}

impl Default for GrpcWebClientLayer {
fn default() -> Self {
Self::new()
Self::default()
}
}

Expand Down
10 changes: 2 additions & 8 deletions tonic-web/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@ use tower_layer::Layer;
use tower_service::Service;

/// Layer implementing the grpc-web protocol.
#[derive(Debug, Clone)]
#[derive(Debug, Default, Clone)]
pub struct GrpcWebLayer {
_priv: (),
}

impl GrpcWebLayer {
/// Create a new grpc-web layer.
pub fn new() -> GrpcWebLayer {
Self { _priv: () }
}
}

impl Default for GrpcWebLayer {
fn default() -> Self {
Self::new()
Self::default()
}
}

Expand Down
9 changes: 2 additions & 7 deletions tonic/src/codec/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,14 @@ pub(crate) fn decompress(
Ok(())
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub(crate) enum SingleMessageCompressionOverride {
/// Inherit whatever compression is already configured. If the stream is compressed this
/// message will also be configured.
///
/// This is the default.
#[default]
Inherit,
/// Don't compress this message, even if compression is enabled on the stream.
Disable,
}

impl Default for SingleMessageCompressionOverride {
fn default() -> Self {
Self::Inherit
}
}
10 changes: 2 additions & 8 deletions tonic/src/metadata/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct MetadataKey<VE: ValueEncoding> {
}

/// A possible error when converting a `MetadataKey` from another type.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct InvalidMetadataKey {
_priv: (),
}
Expand Down Expand Up @@ -180,7 +180,7 @@ impl<VE: ValueEncoding> fmt::Display for MetadataKey<VE> {
impl InvalidMetadataKey {
#[doc(hidden)]
pub fn new() -> InvalidMetadataKey {
InvalidMetadataKey { _priv: () }
Self::default()
}
}

Expand Down Expand Up @@ -275,12 +275,6 @@ impl fmt::Display for InvalidMetadataKey {
}
}

impl Default for InvalidMetadataKey {
fn default() -> Self {
Self::new()
}
}

impl Error for InvalidMetadataKey {}

#[cfg(test)]
Expand Down

0 comments on commit 74d7673

Please sign in to comment.